简体   繁体   中英

Call Service With Options In Zend Framework 3

In ZF3, I am calling a form factory from a controller using this notation:

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

not

    $form = new myForm();

In the factory, I'm using what ZF3 recommends for the method:

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

I assume that the $options array is intended for passing parameters to the function. How do I populate the $options array in the controller?

I think FormManager above also child of ServiceManager . So, instead of using get() like this

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

I think you can use build() . Here the example

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

And the options should be passed in the form factory

public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
    return MyForm($options);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM