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


PHP Form::setHydrator方法代码示例

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


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

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

示例2: createService

 /**
  * Create service
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return mixed
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $form = new Form();
     $form->add(['name' => 'name', 'options' => ['label' => 'Name'], 'attributes' => ['type' => 'text']]);
     $form->add(['name' => 'description', 'options' => ['label' => 'Description'], 'attributes' => ['type' => 'textarea']]);
     $form->add(['name' => 'location', 'options' => ['label' => 'Location'], 'attributes' => ['type' => 'text']]);
     $form->setHydrator(new ClassMethods());
     $form->setInputFilter($this->getInputFilter());
     return $form;
 }
开发者ID:WeCamp,项目名称:Meetspire,代码行数:16,代码来源:GroupFormFactory.php

示例3: testPrepareBindDataAllowsFilterToConvertStringToArray

 public function testPrepareBindDataAllowsFilterToConvertStringToArray()
 {
     $data = array('foo' => '1,2');
     $filteredData = array('foo' => array(1, 2));
     $element = new TestAsset\ElementWithStringToArrayFilter('foo');
     $hydrator = $this->getMock('Zend\\Stdlib\\Hydrator\\ArraySerializable');
     $hydrator->expects($this->any())->method('hydrate')->with($filteredData, $this->anything());
     $this->form->add($element);
     $this->form->setHydrator($hydrator);
     $this->form->setObject(new stdClass());
     $this->form->setData($data);
     $this->form->bindValues($data);
 }
开发者ID:razvansividra,项目名称:pnlzf2-1,代码行数:13,代码来源:FormTest.php

示例4: testCorrectlyHydrateBaseFieldsetWhenHydratorThatDoesNotIgnoreInvalidDataIsUsed

 public function testCorrectlyHydrateBaseFieldsetWhenHydratorThatDoesNotIgnoreInvalidDataIsUsed()
 {
     $fieldset = new Fieldset('example');
     $fieldset->add(array('name' => 'foo'));
     // Add an hydrator that ignores if values does not exist in the
     $fieldset->setObject(new Entity\SimplePublicProperty());
     $fieldset->setHydrator(new \Zend\Stdlib\Hydrator\ObjectProperty());
     $this->form->add($fieldset);
     $this->form->setBaseFieldset($fieldset);
     $this->form->setHydrator(new \Zend\Stdlib\Hydrator\ObjectProperty());
     // Add some inputs that do not belong to the base fieldset
     $this->form->add(array('type' => 'Zend\\Form\\Element\\Submit', 'name' => 'submit'));
     $object = new Entity\SimplePublicProperty();
     $this->form->bind($object);
     $this->form->setData(array('submit' => 'Confirm', 'example' => array('foo' => 'value example')));
     $this->assertTrue($this->form->isValid());
     // Make sure the object was not hydrated at the "form level"
     $this->assertFalse(isset($object->submit));
 }
开发者ID:rcastardo,项目名称:zf2,代码行数:19,代码来源:FormTest.php

示例5: testElementDirectlyInTheForm

 public function testElementDirectlyInTheForm()
 {
     $element = $this->getMoneyFieldset();
     $element->init();
     $form = new Form();
     $form->setHydrator(new ObjectProperty());
     $form->setObject(new StdClass());
     $form->add($element, ['name' => 'money']);
     $this->assertFalse($form->setData([])->isValid());
     $this->assertFalse($form->setData(['money' => ['amount' => '123', 'currency' => '']])->isValid());
     $this->assertFalse($form->setData(['money' => ['amount' => '', 'currency' => 'BRL']])->isValid());
     $data = ['money' => ['amount' => '500.20', 'currency' => 'BRL']];
     $form->setData($data);
     $this->assertTrue($form->isValid());
     $amountValue = $form->get('money')->get('amount')->getValue();
     $currencyValue = $form->get('money')->get('currency')->getValue();
     $object = $form->getData()->money;
     $this->assertSame('500.20', $amountValue);
     $this->assertSame('BRL', $currencyValue);
     $this->assertInstanceOf(Money::class, $object);
     $this->assertSame(50020, $object->getAmount());
     $this->assertSame('BRL', $object->getCurrency()->getName());
 }
开发者ID:zfbrasil,项目名称:doctrine-money-module,代码行数:23,代码来源:FormIntegrationTest.php

示例6: testNestedCollections

 public function testNestedCollections()
 {
     // @see https://github.com/zendframework/zf2/issues/5640
     $addressesFieldeset = new \ZendTest\Form\TestAsset\AddressFieldset();
     $addressesFieldeset->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods());
     $form = new Form();
     $form->setHydrator(new ObjectPropertyHydrator());
     $form->add(array('name' => 'addresses', 'type' => 'Collection', 'options' => array('target_element' => $addressesFieldeset, 'count' => 2)));
     $data = array(array('number' => '0000000001', 'street' => 'street1'), array('number' => '0000000002', 'street' => 'street2'));
     $phone1 = new Phone();
     $phone1->setNumber($data[0]['number']);
     $phone2 = new Phone();
     $phone2->setNumber($data[1]['number']);
     $address1 = new Address();
     $address1->setStreet($data[0]['street']);
     $address1->setPhones(array($phone1));
     $address2 = new Address();
     $address2->setStreet($data[1]['street']);
     $address2->setPhones(array($phone2));
     $customer = new stdClass();
     $customer->addresses = array($address1, $address2);
     $form->bind($customer);
     //test for object binding
     foreach ($form->get('addresses')->getFieldsets() as $_fieldset) {
         $this->assertInstanceOf('ZendTest\\Form\\TestAsset\\Entity\\Address', $_fieldset->getObject());
         foreach ($_fieldset->getFieldsets() as $_childFieldsetName => $_childFieldset) {
             switch ($_childFieldsetName) {
                 case 'city':
                     $this->assertInstanceOf('ZendTest\\Form\\TestAsset\\Entity\\City', $_childFieldset->getObject());
                     break;
                 case 'phones':
                     foreach ($_childFieldset->getFieldsets() as $_phoneFieldset) {
                         $this->assertInstanceOf('ZendTest\\Form\\TestAsset\\Entity\\Phone', $_phoneFieldset->getObject());
                     }
                     break;
             }
         }
     }
     //test for correct extract and populate
     $index = 0;
     foreach ($form->get('addresses') as $_addresses) {
         $this->assertEquals($data[$index]['street'], $_addresses->get('street')->getValue());
         //assuming data has just 1 phone entry
         foreach ($_addresses->get('phones') as $phone) {
             $this->assertEquals($data[$index]['number'], $phone->get('number')->getValue());
         }
         $index++;
     }
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:49,代码来源:CollectionTest.php

示例7: testDoNotCreateExtraFieldsetOnMultipleBind

 public function testDoNotCreateExtraFieldsetOnMultipleBind()
 {
     $form = new \Zend\Form\Form();
     $this->productFieldset->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods());
     $form->add($this->productFieldset);
     $form->setHydrator(new \Zend\Stdlib\Hydrator\ObjectProperty());
     $product = new Product();
     $categories = array(new \ZendTest\Form\TestAsset\Entity\Category(), new \ZendTest\Form\TestAsset\Entity\Category());
     $product->setCategories($categories);
     $market = new \StdClass();
     $market->product = $product;
     // this will pass the test
     $form->bind($market);
     $this->assertSame(count($categories), iterator_count($form->get('product')->get('categories')->getIterator()));
     // this won't pass, but must
     $form->bind($market);
     $this->assertSame(count($categories), iterator_count($form->get('product')->get('categories')->getIterator()));
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:18,代码来源:CollectionTest.php

示例8: testCreatesNewObjectsIfSpecified

 public function testCreatesNewObjectsIfSpecified()
 {
     $this->productFieldset->setUseAsBaseFieldset(true);
     $categories = $this->productFieldset->get('categories');
     $categories->setOptions(array('create_new_objects' => true));
     $form = new \Zend\Form\Form();
     $form->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods());
     $form->add($this->productFieldset);
     $product = new Product();
     $product->setName("foo");
     $product->setPrice(42);
     $cat1 = new \ZendTest\Form\TestAsset\Entity\Category();
     $cat1->setName("bar");
     $cat2 = new \ZendTest\Form\TestAsset\Entity\Category();
     $cat2->setName("bar2");
     $product->setCategories(array($cat1, $cat2));
     $form->bind($product);
     $form->setData(array("product" => array("name" => "franz", "price" => 13, "categories" => array(array("name" => "sepp"), array("name" => "herbert")))));
     $form->isValid();
     $categories = $product->getCategories();
     $this->assertNotSame($categories[0], $cat1);
     $this->assertNotSame($categories[1], $cat2);
 }
开发者ID:rajanlamic,项目名称:IntTest,代码行数:23,代码来源:CollectionTest.php


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