2

在 ZF3 中,我使用以下表示法从控制器调用表单工厂:

    $form = $this->formManager->get(myForm::class);

不是

    $form = new myForm();

在工厂中,我使用的是 ZF3 推荐的方法:

    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
       //...
    }

我假设该$options数组旨在将参数传递给函数。如何$options在控制器中填充数组?

4

1 回答 1

3

我想FormManager上面也是ServiceManager. 所以,而不是get()像这样使用

$form = $this->formManager->get(myForm::class);

我认为你可以使用build(). 这里的例子

$form = $this->formManager->build(myForm::class, $options);

并且选项应该在表单工厂中传递

public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
    return MyForm($options);
}
于 2018-02-08T01:13:11.507 回答