1
請解釋我怎麼可以綁定值這樣的形式:ZF2形式收集結合
<?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',
),
));
}
}
,並在控制器中我使用
$feelist_form = new \ZfcAdmin\Form\FeelistUploadForm($objectManager);
$feelist_form->bind(new feelist());
字段集
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 = $objectManager
->getRepository('InsurancyProduct\Entity\Feelist')
->findBy(array('product_id' => $id));
我無法將它綁定到表單,它是對象數組,但表單只能接收單個對象。 窗體當然是空的,我不知道如何綁定這個值來形成。請不要送我去RFTM,我一直在閱讀它過去的48小時,約ZF2水化,表格等:(