Can someone explain to me how to fix this error "No object manager was set"
Here is the fieldset:
namespace Trunk\Form;
use Trunk\Entity\Category;
use Doctrine\Common\Persistence\ObjectManager;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
use Zend\Form\Fieldset;
use Zend\InputFilter\InputFilterProviderInterface;
class CategoryFieldset extends Fieldset implements InputFilterProviderInterface
{
public function __construct($objectManager)
{
parent::__construct('category');
$this->setHydrator(new DoctrineHydrator($objectManager, 'Trunk\Entity\Category'));
$this->add(array(
'type' => 'DoctrineORMModule\Form\Element\DoctrineEntity',
'name' => 'title',
'object_manager' => $objectManager,
'target_class' => 'Trunk\Entity\Category',
'property' => 'title',
'is_method' => false,
'find_method' => array(
'name' => 'findBy',
'params' => array(
'criteria' => array('parentid' => 0),
'orderBy' => array('title' => 'ASC'),
),
)
));
}
}
Here is the error message:
F:\xampp\htdocs\travelltheworld\vendor\doctrine\doctrine-module\src\DoctrineModule\Form\Element\Proxy.php:535
No object manager was set
I have injected the entity manager in the factory into my form which is called ProductForm. Inside that form I have base fieldset called ProductFieldset and inside ProductFieldset I inserted CategoryFieldset where I need to select the categories from the Database and display them in the select box.
If you need more code or explanation please ask me.
Fieldset object can hydrate your entities with an Hydrator.
Here is a complete example of a fieldset https://github.com/Grafikart/BlogMVC/blob/master/ZendFramework2/module/Blog/src/Blog/Form/Fieldset/CommentFieldset.php
As you can see the fieldset can have the Object manager by an "awareInterface" named ObjectManagerAwareInterface
,
use DoctrineModule\Persistence\ObjectManagerAwareInterface;
and the trait : use ProvidesObjectManager;
use DoctrineModule\Persistence\ProvidesObjectManager as ProvidesObjectManager ;
you have miss those in your fieldset, this should correct your problem.
Your form, and his factory are completely different than the fieldset so it can't work that way for you construct injection.