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


PHP Form::getObject方法代码示例

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


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

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

示例2: processForm

 protected function processForm(Form $form, $options = array(), $extra1 = null, $extra2 = array())
 {
     /**
      * Special case for a simpler API: if the second argument is a string, it is used as the route to redirect
      * to, the third argument as the route parameters and the fourth argument as additional options.
      */
     if (is_string($options)) {
         $options = array('redirect_route' => $options, 'redirect_params' => $extra1);
         $options = $options + $extra2;
     }
     if ($options && isset($options['object_manager'])) {
         $objectManager = $options['object_manager'];
     } else {
         $objectManager = $this->getEntityManager();
     }
     /** @var $request Request */
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $form->bindValues();
             $objectManager->persist($form->getObject());
             $objectManager->flush();
             if (!empty($options['success_message'])) {
                 $this->flashMessenger()->addMessage($options['success_message']);
             }
             if (!empty($options['redirect_route'])) {
                 $params = array();
                 if (!empty($options['redirect_params'])) {
                     $params = $options['redirect_params'];
                     if (is_callable($params)) {
                         $params = call_user_func($params, $form);
                     }
                 }
                 return $this->redirect()->toRoute($options['redirect_route'], $params);
             }
         }
     }
     return null;
 }
开发者ID:rieschl,项目名称:admin-module,代码行数:40,代码来源:AbstractAdminController.php

示例3: getFormObject

 /**
  * Возвращает объект привязанный к форме
  *
  * @param Form $form
  *
  * @return mixed
  * @throws \Assert\AssertionFailedException
  */
 protected function getFormObject(Form $form)
 {
     $form->bindValues();
     $object = $form->getObject();
     Assertion::isInstanceOf($object, GitLabDto::class);
     return $object;
 }
开发者ID:old-town-gitlab-tools,项目名称:core,代码行数:15,代码来源:UpdateController.php


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