本文整理汇总了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);
}
示例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());
}
示例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;
}
示例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']);
}