I have the following setup:
Module.php
class Module implements ServiceProviderInterface,
FormElementProviderInterface
{
public function getFormElementConfig()
{
return array(
'invokables' => array(
'GenreFieldSet' => 'Cms\Form\GenreFieldSet',
),
'initializers' => array(
'ObjectManagerInitializer' => function ($element,
$formElements)
{
if ($element instanceof ObjectManagerAwareInterface)
{
$services = $formElements->getServiceLocator();
$entityManager =
$services->get('Doctrine\ORM\EntityManager');
$element->setObjectManager($entityManager);
}
},
),
);
}
}
Controller:
/**
* Method called to edit a Genre
*
* @return ViewModel
*/
public function editAction()
{
$formManager =
$this->getServiceLocator()->get('FormElementManager');
$form = $formManager->get('Cms\Form\GenreForm');
...
}
Form:
class GenreForm extends Form
{
public function init()
{
$this->add(array(
'name' => 'genre',
'type' => 'GenreFieldSet',
));
$this->add(array(
'name' => 'submit',
'type' => 'Submit',
'attributes' => array(
'value' => 'Go',
'id' => 'submitbutton',
),
));
}
}
FieldSet:
class GenreFieldSet extends Fieldset implements
ObjectManagerAwareInterface, InputFilterProviderInterface
{
/**
* @var InputFilter
*
*/
protected $inputFilter;
/**
* @var ObjectManager
*
*/
protected $objectManager;
public function __construct()
{
$this->setHydrator(new
DoctrineEntity($this->getObjectManager()))->setObject(new Genre());
$this->addElements();
}
public function addElements()
{
...
}
public function getInputFilterSpecification()
{
...
}
/**
* Get objectManager
*
* @return type
*/
public function getObjectManager()
{
return $this->objectManager;
}
/**
* Set objectManager
*
* @param ObjectManager $objectManager
* @return \Cms\Services\AntenneService
*/
public function setObjectManager(ObjectManager $objectManager)
{
$this->objectManager = $objectManager;
return $this;
}
}
I keep getting the following exception:
( ! ) Catchable fatal error: Argument 1 passed to
DoctrineModule\Stdlib\Hydrator\DoctrineObject::__construct() must be an
instance of Doctrine\Common\Persistence\ObjectManager, null given
Meaning the intializer in the Module didn't set the ObjectManager properly.
Does somebody know what to do?
Thanks!!
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.