当前位置: 首页>>代码示例>>PHP>>正文


PHP Form::setData方法代码示例

本文整理汇总了PHP中Zend\Form\Form::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::setData方法的具体用法?PHP Form::setData怎么用?PHP Form::setData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Form\Form的用法示例。


在下文中一共展示了Form::setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setData

 public function setData($data)
 {
     if ($data instanceof Traversable) {
         $data = ArrayUtils::iteratorToArray($data);
     }
     $isAts = isset($data['atsEnabled']) && $data['atsEnabled'];
     $isUri = isset($data['uriApply']) && !empty($data['uriApply']);
     $email = isset($data['contactEmail']) ? $data['contactEmail'] : '';
     if ($isAts && $isUri) {
         $data['atsMode']['mode'] = 'uri';
         $data['atsMode']['uri'] = $data['uriApply'];
         $uri = new Http($data['uriApply']);
         if ($uri->getHost() == $this->host) {
             $data['atsMode']['mode'] = 'intern';
         }
     } elseif ($isAts && !$isUri) {
         $data['atsMode']['mode'] = 'intern';
     } elseif (!$isAts && !empty($email)) {
         $data['atsMode']['mode'] = 'email';
         $data['atsMode']['email'] = $email;
     } else {
         $data['atsMode']['mode'] = 'none';
     }
     if (!array_key_exists('job', $data)) {
         $data = array('job' => $data);
     }
     return parent::setData($data);
 }
开发者ID:utrenkner,项目名称:YAWIK,代码行数:28,代码来源:Import.php

示例2: validate

 public function validate($data)
 {
     $this->form->setData($data);
     $isValid = $this->form->isValid();
     $normalized = $this->form->getData();
     unset($normalized['ViewReportControl']);
     $validated = new \SSRS\Form\ValidateResult();
     $validated->isValid = $isValid;
     $validated->parameters = $normalized;
     return $validated;
 }
开发者ID:caseypage,项目名称:php-ssrs-1,代码行数:11,代码来源:ZendFramework2.php

示例3: add

 /**
  * @param \Zend\Form\Form $form
  * @param $data
  * @return Entity\Comment|null
  * @throws \Exception
  */
 public function add(\Zend\Form\Form $form, $data)
 {
     $serviceLocator = $this->getServiceLocator();
     $entityManager = $serviceLocator->get('Doctrine\\ORM\\EntityManager');
     $entityType = $entityManager->getRepository('\\Comment\\Entity\\EntityType')->findOneByAlias($data['alias']);
     if (!$entityType) {
         throw new EntityNotFoundException();
     }
     $form->setData($data);
     if ($form->isValid()) {
         if ($entityType->getIsEnabled()) {
             $data = $form->getData();
             $comment = new Entity\Comment();
             $comment->setEntityType($entityType);
             $user = $serviceLocator->get('Zend\\Authentication\\AuthenticationService')->getIdentity()->getUser();
             $comment->setUser($user);
             $comment->setComment($data['comment']);
             $entityManager->getConnection()->beginTransaction();
             try {
                 $hydrator = new DoctrineHydrator($entityManager);
                 $hydrator->hydrate($data, $comment);
                 $entityType->getComments()->add($comment);
                 $entityManager->persist($comment);
                 $entityManager->persist($entityType);
                 $entityManager->flush();
                 $entityManager->getConnection()->commit();
                 return $comment;
             } catch (\Exception $e) {
                 $entityManager->getConnection()->rollback();
                 throw $e;
             }
         }
     }
     return null;
 }
开发者ID:zfury,项目名称:cmf,代码行数:41,代码来源:Comment.php

示例4: create

 /**
  * Create a new image
  *
  * @param array $data
  * @param \Zend\Form\Form $form
  * @return bool
  */
 public function create($data, &$form)
 {
     $entity = new ImageEntity();
     $em = $this->getEntityManager();
     $form->bind($entity);
     $form->setData($data);
     if (!$form->isValid()) {
         return false;
     }
     // we rename the file with a unique name
     $newName = FileUtilService::rename($data['image']['image'], 'images/gallery', "gallery");
     foreach (ImageEntity::$thumbnailVariations as $variation) {
         $result = FileUtilService::resize($newName, 'images/gallery', $variation["width"], $variation["height"]);
         if (!$result) {
             $this->message = $result;
             return false;
         }
     }
     $entity->setImage($newName);
     try {
         $em->persist($entity);
         $em->flush();
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_IMAGE_CREATED"]);
         return true;
     } catch (\Exception $e) {
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_IMAGE_NOT_CREATED"]);
         return false;
     }
 }
开发者ID:JoshBour,项目名称:karolina,代码行数:36,代码来源:ImageService.php

示例5: create

 /**
  * Create a new post
  *
  * @param array $data
  * @param \Zend\Form\Form $form
  * @return bool
  */
 public function create($data, &$form)
 {
     $post = new PostEntity();
     $em = $this->getEntityManager();
     $form->bind($post);
     $form->setData($data);
     if (!$form->isValid()) {
         return false;
     }
     // we rename the file with a unique name
     $newName = FileUtilService::rename($data['post']['thumbnail'], 'images/posts', "post");
     foreach (PostEntity::$thumbnailVariations as $variation) {
         $result = FileUtilService::resize($newName, 'images/posts', $variation["width"], $variation["height"]);
         if (!$result) {
             $this->message = $result;
             return false;
         }
     }
     $post->setThumbnail($newName);
     $post->setPostDate("now");
     $post->setUrl($this->getPostUrl($post));
     try {
         $em->persist($post);
         $em->flush();
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_POST_CREATED"]);
         return true;
     } catch (\Exception $e) {
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_POST_NOT_CREATED"]);
         return false;
     }
 }
开发者ID:JoshBour,项目名称:karolina,代码行数:38,代码来源:PostService.php

示例6: testPreserveEntitiesBoundToCollectionAfterValidation

 public function testPreserveEntitiesBoundToCollectionAfterValidation()
 {
     $this->form->setInputFilter(new \Zend\InputFilter\InputFilter());
     $fieldset = new TestAsset\ProductCategoriesFieldset();
     $fieldset->setUseAsBaseFieldset(true);
     $product = new Entity\Product();
     $product->setName('Foobar');
     $product->setPrice(100);
     $c1 = new Entity\Category();
     $c1->setId(1);
     $c1->setName('First Category');
     $c2 = new Entity\Category();
     $c2->setId(2);
     $c2->setName('Second Category');
     $product->setCategories(array($c1, $c2));
     $this->form->add($fieldset);
     $this->form->bind($product);
     $data = array('product' => array('name' => 'Barbar', 'price' => 200, 'categories' => array(array('name' => 'Something else'), array('name' => 'Totally different'))));
     $hash1 = spl_object_hash($this->form->getObject()->getCategory(0));
     $this->form->setData($data);
     $this->form->isValid();
     $hash2 = spl_object_hash($this->form->getObject()->getCategory(0));
     // Returned object has to be the same as when binding or properties
     // will be lost. (For example entity IDs.)
     $this->assertTrue($hash1 == $hash2);
 }
开发者ID:rajanlamic,项目名称:IntTest,代码行数:26,代码来源:FormTest.php

示例7: setData

 public function setData($data)
 {
     $parsedData = $data;
     if ($data instanceof AbstractSiteOptions) {
         $parsedData = array('config' => $data->toArray());
     }
     return parent::setData($parsedData);
 }
开发者ID:xelax90,项目名称:xelax-site-config,代码行数:8,代码来源:AbstractSiteConfigForm.php

示例8: updateAction

 public function updateAction()
 {
     if (!($seo = $this->loadObject($this->seoService, "Seo record doesn't exist."))) {
         return $this->redirect()->toRoute('seo', array('action' => 'list'));
     }
     $this->seoForm->bind($seo);
     if ($this->request->isPost()) {
         $this->seoForm->setData($this->request->getPost());
         if ($this->seoForm->isValid()) {
             $this->seoService->update($this->seoForm->getData());
             $this->flashMessenger()->addSuccessMessage(sprintf('Seo "%s" has been successfully updated.', $seo->getId()));
             return $this->redirect()->toRoute('seo', array('action' => 'list'));
         }
     }
     $view = new ViewModel(array('id' => $seo->getId(), 'form' => $this->seoForm));
     $view->setTerminal(true);
     return $view;
 }
开发者ID:nsenkevich,项目名称:seo,代码行数:18,代码来源:SeoController.php

示例9: checkFormIsValid

 /**
  * Metodo para validar o isPost e isValid
  *
  * @param Form $form Formulario a ser validado
  *
  * @return int 0 -> invalid, 1 valid, 2 not isPost
  */
 public function checkFormIsValid(Form $form)
 {
     $objRequest = $this->getRequest();
     if ($objRequest->isPost()) {
         $form->setData($objRequest->getPost());
         return $form->isValid() ? self::CHECK_FORM_IS_VALID : self::CHECK_FORM_IS_NOT_VALID;
     } else {
         return self::CHECK_FORM_IS_NOT_POST;
     }
 }
开发者ID:diego-mi,项目名称:financeiro,代码行数:17,代码来源:AbstractFormController.php

示例10: setData

 /**
  * @param array|\ArrayAccess|\Traversable $data
  * @return Form
  */
 public function setData($data)
 {
     //Set default values
     foreach ($this->getDefaults() as $index => $value) {
         if (!isset($data[$index])) {
             $data[$index] = $value;
         }
     }
     return parent::setData($data);
 }
开发者ID:sarancea,项目名称:ciklum,代码行数:14,代码来源:AbstractForm.php

示例11: setData

 public function setData($data)
 {
     if ($data instanceof Traversable) {
         $data = ArrayUtils::iteratorToArray($data);
     }
     if (!array_key_exists('job', $data)) {
         $data = array('job' => $data);
     }
     return parent::setData($data);
 }
开发者ID:bitrecruiter,项目名称:CrossApplicantManager,代码行数:10,代码来源:Import.php

示例12: preReset

 /**
  * @param  Params                          $params
  * @param  Form                            $form
  * @param  \FzyAuth\Service\Password\Reset $reset
  * @return \Zend\Http\Response|ViewModel
  */
 protected function preReset(Params $params, Form $form, \FzyAuth\Service\Password\Reset $reset)
 {
     if (!trim($params->get('token')) || $reset->getUserByToken($params->get('token'))->isNull()) {
         return $this->redirect()->toRoute(UserController::ROUTE_LOGIN);
     }
     $form->setData($params->get());
     $view = new ViewModel(array('changePasswordForm' => $form));
     $view->setTemplate('fzy-auth/password/reset');
     return $view;
 }
开发者ID:fousheezy,项目名称:auth,代码行数:16,代码来源:PasswordController.php

示例13: login

 /**
  * @param \Zend\Form\Form $form
  * @param $data
  * @return bool
  */
 public function login(&$form, $data)
 {
     $user = new User();
     $form->bind($user);
     $form->setData($data);
     if ($form->isValid()) {
         return true;
     } else {
         return false;
     }
 }
开发者ID:JoshBour,项目名称:karolina,代码行数:16,代码来源:Auth.php

示例14: checkFormIsValid

 /**
  * Metodo para validar o isPost e isValid
  *
  * @param Form $form Formulario a ser validado
  *
  * @return Form
  */
 public function checkFormIsValid(Form $form)
 {
     $objRequest = $this->getRequest();
     if ($objRequest->isPost()) {
         $form->setData($objRequest->getPost());
         if ($form->isValid()) {
             return true;
         }
     }
     return false;
 }
开发者ID:diego-mi,项目名称:zend-skeleton-base,代码行数:18,代码来源:AbstractFormController.php

示例15: saveAction

 public function saveAction(Request $request, Create $createService, Form $form, View $view, Redirect $redirect)
 {
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $createService->create($form->getData());
             return $redirect->toRoute('admin-translate-words');
         }
     }
     $view->setForm($form);
     $view->setTemplate('translate/admin/word/edit');
     return $view;
 }
开发者ID:sebaks,项目名称:Translate,代码行数:13,代码来源:WordController.php


注:本文中的Zend\Form\Form::setData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。