Please, explain me how i can bind values to such a form:
<?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',
),
));
}
}
and the fieldset
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(
);
}
}
in the controller i use
$feelist_form = new \ZfcAdmin\Form\FeelistUploadForm($objectManager);
$feelist_form->bind( new feelist());
and i can get values for bind in controller like this
$feelist = $objectManager
->getRepository('InsurancyProduct\Entity\Feelist')
->findBy(array('product_id' => $id));
i can't bind it to form, it's array of objects, but form recieves only single object. form is of course empty and i dont know how to bind this values to form. Please, dont send me to RFTM, I have been reading it for last 48 hours, about zf2 hydration, forms, etc :(