Zend framework2 如何将选项传递到表单管理器创建的表单中的集合字段集?
我已通过以下方式在控制器中创建/调用表单:Zend framework2 如何将选项传递到表单管理器创建的表单中的集合字段集?,zend-framework2,zend-form,Zend Framework2,Zend Form,我已通过以下方式在控制器中创建/调用表单: class MyController extends AbstractActionController { function IndexAction() { $form = $this ->getServiceLocator() ->get('FormElementManager') ->get('MyForm
class MyController extends AbstractActionController {
function IndexAction() {
$form = $this
->getServiceLocator()
->get('FormElementManager')
->get('MyForm',['option1'=>123);
}
}
下一步-在表单中,我可以访问已通过的选项:
class MyForm extends Form implements ServiceLocatorAwareInterface
{
use ServiceLocatorAwareTrait;
public function init()
{
$option1 = $this->getOption('option1'); // I have here "123" !!!
$this->add(
[
'name' => 'Child',
'type' => 'Zend\Form\Element\Collection',
'options' => [
'label' => 'Child',
'count' => 1,
'should_create_template' => true,
'allow_add' => true,
'template_placeholder' => '__placeholder__',
'target_element' => [
'type' => 'MyFieldset',
],
],
]
);
}
}
但在fieldset中,很遗憾-不:
class MyFieldset extends Fieldset implements ServiceLocatorAwareInterface
{
use ServiceLocatorAwareTrait;
public function init()
{
$option1 = $this->getOption('option1'); // Empty :(
}
}
那么-如何实现对fieldset中“option1”的访问