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


PHP Form::setObject方法代码示例

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


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

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

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

示例3: hydrate

 /**
  * Hydrate an array of data onto an entity using a form
  *
  * @param AbstractEntity $entity
  * @param array $values
  * @param Form $form
  * @return AbstractEntity
  */
 private function hydrate(AbstractEntity $entity, array $values, Form $form)
 {
     $form->setObject($entity);
     if ($form->getBaseFieldset()) {
         $form->getBaseFieldset()->setObject($entity);
     }
     $form->setData($values);
     if (!$form->isValid()) {
         return $this->setErrorMessages($form->getMessages());
     }
     $result = $form->getData();
     if (!$result instanceof AbstractEntity) {
         throw new RuntimeException('Unable to retrieve entity from Form');
     }
     return $result;
 }
开发者ID:outeredge,项目名称:edge-zf2,代码行数:24,代码来源:AbstractRepositoryService.php

示例4: testFormAsFieldsetWillBindValuesToObject

 public function testFormAsFieldsetWillBindValuesToObject()
 {
     $parentForm = new Form('parent');
     $parentFormObject = new \ArrayObject(array('parentId' => null));
     $parentFormElement = new Element('parentId');
     $parentForm->setObject($parentFormObject);
     $parentForm->add($parentFormElement);
     $childForm = new Form('child');
     $childFormObject = new \ArrayObject(array('childId' => null));
     $childFormElement = new Element('childId');
     $childForm->setObject($childFormObject);
     $childForm->add($childFormElement);
     $parentForm->add($childForm);
     $data = array('parentId' => 'mpinkston was here', 'child' => array('childId' => 'testing 123'));
     $parentForm->setData($data);
     $this->assertTrue($parentForm->isValid());
     $this->assertEquals($data['parentId'], $parentFormObject['parentId']);
     $this->assertEquals($data['child']['childId'], $childFormObject['childId']);
 }
开发者ID:rcastardo,项目名称:zf2,代码行数:19,代码来源:FormTest.php


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