Closed josemsalves closed 1 year ago
@josemsalves
I had a short look in your sample code, but the code under https://github.com/josemsalves/testes has several other (non-related) issues - a simple docker compose up -d
doesn't get it running to repreduce the error you mentioned above. Please note that your application is outdated, as it is still using PHP 7.4. I recommend re-creating the project from the laminas-skeleton-application, to enable use of PHP 8.1.
Regarding your error message Call to a member function setValue() on null
, you should provide a traceback to show the relevant class/method where the error occurs. One think that I see as problematic in your code snippets above is that you are creating the fieldsets with new ClassName()
. Please take a look at the Laminas form documentation on how to use custom elements: https://docs.laminas.dev/laminas-form/v3/advanced/#creating-custom-elements. Elements should be created through the form factory, which initializes the elements correctly.
You should do something like this:
$this->add([
'type' => \Laminas\Form\Element\Collection::class,
'name' => 'mySubFieldsetElement',
'options' => [
'allow_add' => true,
'allow_remove' => true,
'target_element' => [
'type' => \Application\Form\MySubFieldset::class,
],
],
]);
Or, in case you need the target element object itself, try this:
$targetElement = $this->getFormFactory()->getFormElementManager()->get(\Application\Form\MySubFieldset::class);
$this->add([
'type' => \Laminas\Form\Element\Collection::class,
'name' => 'mySubFieldsetElement',
'options' => [
'allow_add' => true,
'allow_remove' => true,
'target_element' => $targetElement,
],
]);
Live, I'm using laminas-doctrine-hydrator with 2-level collections in one-to-many relationships. The 2nd level fieldset gives the error "Call to a member function setValue() on null". Is there any limitation? As classes:
o form e fieldset: