【发布时间】:2013-12-23 18:14:43
【问题描述】:
请解释我如何将值绑定到这样的表单:
<?php
namespace ZfcAdmin\Form;
use Zend\Form\Form;
use Zend\Form\Element;
class FeelistUploadForm extends Form {
public function __construct($objectManager) {
parent::__construct('feelist');
$this->setAttribute('method', 'post');
$this->setAttribute('class', 'form');
$fieldset = new FeelistFieldset($objectManager);
$fieldset->setUseAsBaseFieldset(true);
$this->add(array(
'type' => 'Zend\Form\Element\Collection',
'name' => 'feelist',
'options' => array(
'label' => 'fee list',
'should_create_template' => true,
'allow_add' => true,
'target_element' => $fieldset,
),
));
$this->add(array(
'name' => 'submit',
'type' => 'Submit',
'attributes' => array(
'value' => 'Save',
'id' => 'submitbutton',
'class' => 'button',
),
));
}
}
和字段集
class FeelistFieldset extends Fieldset implements InputFilterProviderInterface {
public function __construct($objectManager, $options = array()) {
$this->setHydrator(new DoctrineHydrator($objectManager, 'InsurancyProduct\Entity\Feelist'))
->setObject(new Feelist());
parent::__construct('feelist');
$this->add(array(
'name' => 'id',
'type' => 'Hidden',
));
$this->add(array(
'name' => 'csv',
'type' => 'Zend\Form\Element\File',
'options' => array(
'label' => 'csv',
),
));
$this->add(array(
'type' => 'text',
'name' => 'valid_from',
'options' => array(
'label' => 'valid from',
),
'attributes'=> array(
'id' => 'validfrom',
),
));
}
public function getInputFilterSpecification()
{
return array(
);
}
}
在我使用的控制器中
$feelist_form = new \ZfcAdmin\Form\FeelistUploadForm($objectManager);
$feelist_form->bind( new feelist());
我可以像这样在控制器中获取绑定值
$feelist = $objectManager
->getRepository('InsurancyProduct\Entity\Feelist')
->findBy(array('product_id' => $id));
我不能将它绑定到表单,它是对象数组,但表单只接收单个对象。 表单当然是空的,我不知道如何将这些值绑定到表单。请不要把我发给 RFTM,我在过去 48 小时里一直在阅读它,关于 zf2 水合作用、表格等:(
【问题讨论】:
标签: php zend-framework2