2
votes

I'm using Zend, Doctrine2.1 and AnnotationForms.

My entity looks like this:

/**
 * @ORM\Entity
 * @ORM\Table(name="myentity")
 * @Form\Name("myentity")
 * @Form\Attributes({ "class": "form-horizontal" })
 * @Form\Hydrator("\DoctrineModule\Stdlib\Hydrator\DoctrineObject")
*/
class MyEntity {
   ...
}

When using this DoctrineObject I get the following error:

Catchable fatal error: Argument 1 passed to DoctrineModule\Stdlib\Hydrator\DoctrineObject::__construct() must be an instance of Doctrine\Common\Persistence\ObjectManager, none given, called in C:\vendor\zendframework\zendframework\library\Zend\Form\Factory.php on line 566 and defined in C:\vendor\doctrine\doctrine-module\src\DoctrineModule\Stdlib\Hydrator\DoctrineObject.php on line 63

I cannot use Zend\Stdlib\Hydrator\ObjectProperty because then I get

Fatal error: Cannot access protected property

I'm quite lost. Anybody an idea what I can do to fix this issue?

I'm guessing that I need a __construct() function. But what do I put in there?

3
1) Can you confirm you instantiate the form through the FormElementManager service? 2) Have you tried registering the DoctrineModule\Stdlib\Hydrator\DoctrineObject as a factory?emix

3 Answers

3
votes

Someone may come up with a Annotation-only function, if that exists, meanwhile you can go this approach:

$form = //create the annotation form WITHOUT a hydrator
$objectManager = $serviceLocator->get('Doctrine\ORM\EntityManager');
$hydrator = new \DoctrineModule\Stdlib\Hydrator\DoctrineObject($objectManager);
$form->setHydrator($hydrator);

//continue in your controller
0
votes

Had also problems with the annotation forms. My solution was a mindbreaker. Took me long time to find out. My problem was in the first line of the annotation code.

/**

This line is normally used for commenting your annotation code, but allmost everybody leaves it empty. Normally no issues, but this is somehow causing problems in the form annotations. You should either add some comment, add a space, or move your first line of code up. So:

/** Some comment to make this annotation work
/** (<-- a space)

or start like this:

/** @ORM\Entity

Don't ask me why this is happening (some parsing error?). I found this on a post on GitHub where someone reported having similar issue (https://github.com/doctrine/common/issues/331). As I understood the bug is not a doctrine but a ZF2 issue and it has been reported.

Not sure this is your issue as well, but posting this was the least i could do...

-1
votes

Please have a look at this solution, it's preatty good