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


PHP Form::bind方法代码示例

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


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

示例1: setModel

 /**
  * @param mixed $model
  */
 public function setModel($model)
 {
     $modelClass = get_class($model);
     $this->form = $this->annotationBuilder->createForm($modelClass);
     $this->form->bind($model);
     $this->setVariables(['form' => $this->form, 'object' => $model, 'title' => $this->getFieldSetTitle($model)]);
     $this->buildFormViewModel($this->form, $this);
 }
开发者ID:adacap,项目名称:3agest-prototype,代码行数:11,代码来源:FormModel.php

示例2: getNoteForm

 /**
  * @param Entity\Note $note
  * @param string $url
  * @param string $action
  * @param array $members
  * @return \Zend\Form\Form
  */
 public function getNoteForm(Entity\Note $note, $url = '', $action = 'add', $members = null)
 {
     if (is_null($this->noteForm)) {
         $builder = new AnnotationBuilder($this->getEntityManager());
         $this->noteForm = $builder->createForm($note);
         $this->noteForm->setAttribute('action', $url);
         $this->noteForm->setAttribute('id', 'noteForm');
         $this->noteForm->setHydrator(new DoctrineObject($this->getEntityManager(), 'Secretary\\Entity\\Note'));
         $this->noteForm->bind($note);
         if ($action == 'edit' && $note->getPrivate() === false) {
             $this->noteForm->remove('private');
             $group = $note->getGroup();
             $membersString = $this->getMembersString(array_keys($members));
             $this->noteForm->get('groupHidden')->setValue($group->getId());
             $this->noteForm->get('members')->setValue($membersString);
             $this->noteForm->getInputFilter()->remove('__initializer__');
             $this->noteForm->getInputFilter()->remove('__cloner__');
             $this->noteForm->getInputFilter()->remove('__isInitialized__');
             $this->noteForm->getInputFilter()->remove('lazyPropertiesDefaults');
         } else {
             $this->noteForm->get('private')->setAttribute('required', false);
             $this->noteForm->getInputFilter()->get('private')->setRequired(false);
         }
     }
     return $this->noteForm;
 }
开发者ID:dotuancd,项目名称:secretary,代码行数:33,代码来源:Note.php

示例3: 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

示例4: bind

 /**
  * Bind an object to the form
  *
  * Ensures the object is populated with validated values.
  * Set isEditForm to true so that edit form is distinguished
  * 
  * @param  object $object
  * @param  int $flags ,default value is FormInterface::VALUES_NORMALIZED
  * @param  bool $isEditForm ,default value is true
  * @return mixed|void
  * @throws Exception\InvalidArgumentException
  */
 public function bind($object, $flags = FormInterface::VALUES_NORMALIZED, $isEditForm = true)
 {
     if ($isEditForm === true) {
         $this->isEditForm = true;
     }
     parent::bind($object, $flags);
 }
开发者ID:camelcasetechsd,项目名称:certigate,代码行数:19,代码来源:Form.php

示例5: 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

示例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: bind

 /**
  * (non-PHPdoc)
  *
  * @see \Zend\Form\Form::bind()
  */
 public function bind($object, $flags = FormInterface::VALUES_NORMALIZED)
 {
     if (null != $object->getId() && null != $this->get('submit')) {
         $this->get('submit')->setAttribute('value', 'BTN_UPDATE');
     }
     parent::bind($object, $flags);
 }
开发者ID:DavBfr,项目名称:BlogMVC,代码行数:12,代码来源:BaseForm.php

示例8: bind

 public function bind($object, $flags = FormInterface::VALUES_NORMALIZED)
 {
     foreach ($this->getFieldsets() as $fieldset) {
         $fieldset->setObject($object);
     }
     $result = parent::bind($object, $flags);
     return $result;
 }
开发者ID:modelframework,项目名称:modelframework,代码行数:8,代码来源:DataForm.php

示例9: 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

示例10: getForm

 /**
  * Returns a form for the current entity with an input filter set
  * built using the provided annotations in model
  *
  * @return Form
  */
 public function getForm()
 {
     if (empty($this->form)) {
         $builder = new AnnotationBuilder();
         $this->form = $builder->createForm($this);
         $this->form->bind($this);
     }
     return $this->form;
 }
开发者ID:parnustk,项目名称:lisbackend,代码行数:15,代码来源:EntityValidation.php

示例11: getForm

 /**
  * @return \Zend\Form\Form
  */
 public function getForm($entity)
 {
     if ($this->form->hasValidated()) {
         return $this->form;
     }
     $this->form->bind($entity);
     $this->form->bindOnValidate();
     $this->getEventManager()->trigger($this->createEvent(CrudEvent::FORM_READY, $this->form));
     return $this->form;
 }
开发者ID:phpro,项目名称:zf-smartcrud,代码行数:13,代码来源:AbstractSmartService.php

示例12: 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

示例13: createFromForm

 /**
  * createFromForm
  *
  * @param Form $form
  * @return CdliTwoStageSignup\Model\EmailVerification
  */
 public function createFromForm(Form $form)
 {
     $form->bind(new Model());
     if (!$form->isValid()) {
         return false;
     }
     $model = $form->getData();
     $model->generateRequestKey();
     $this->getEventManager()->trigger(__FUNCTION__, $this, array('record' => $model, 'form' => $form));
     $this->getEmailVerificationMapper()->insert($model);
     return $model;
 }
开发者ID:cdli,项目名称:cdlitwostagesignup,代码行数:18,代码来源:EmailVerification.php

示例14: editAction

 /**
  * Edit
  * 
  * @return ViewModel
  */
 public function editAction()
 {
     $object = $this->getObject();
     if ($this->form) {
         $this->form->bind($object);
     }
     $request = $this->getRequest();
     if ($request->isPost()) {
         if ($response = $this->processForm()) {
             return $response;
         }
     }
     $viewModel = new ViewModel();
     $viewModel->setTemplate($this->templates['edit']);
     $viewModel->setVariables(array('form' => $this->form, 'object' => $object, 'templates' => $this->templates, 'routes' => $this->routes));
     return $viewModel;
 }
开发者ID:nicovogelaar,项目名称:crud-controller-module,代码行数:22,代码来源:AbstractCrudController.php

示例15: bind

 public function bind($object, $flags = FormInterface::VALUES_NORMALIZED)
 {
     parent::bind($object, $flags);
     $pluginClasses = $this->getAttribute(static::BIND_PLUGIN_CLASSES);
     if (!empty($pluginClasses)) {
         if (!is_array($pluginClasses)) {
             throw new \InvalidArgumentException('The plugin classes attribute must be an array');
         }
         foreach ($pluginClasses as $pluginClass) {
             if (!is_subclass_of($pluginClass, '\\Zork\\Form\\Plugin\\BindInterface')) {
                 throw new \InvalidArgumentException('The plugin class must be implement \\Zork\\Form\\Plugin\\BindInterface');
             }
             $plugin = new $pluginClass();
             $plugin->bind($this);
         }
     }
     return $this;
 }
开发者ID:gridguyz,项目名称:zork,代码行数:18,代码来源:Form.php


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