2

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?

Dolly Aswin
  • 2,684
  • 1
  • 20
  • 23
jcropp
  • 1,236
  • 2
  • 10
  • 29

1 Answers1

3

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);
}
Dolly Aswin
  • 2,684
  • 1
  • 20
  • 23