Zend Framework 2 - 注释形式和Doctrine2 - 可追踪的致命错误 - ObjectManager [英] Zend Framework 2 - Annotation forms and Doctrine2 - Catchable fatal error - ObjectManager

查看:175
本文介绍了Zend Framework 2 - 注释形式和Doctrine2 - 可追踪的致命错误 - ObjectManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Zend,Doctrine2.1和AnnotationForms。

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 {
   ...
}

当使用这个 DoctrineObject 时,我收到以下错误:

When using this DoctrineObject I get the following error:


可能的致命错误:参数1传递给DoctrineModule\Stdlib\Hydrator\DoctrineObject :: __ construct()必须是Doctrine\Common\Persistence\ObjectManager的实例,没有给出,C:在线566上定义的\\vendor\zendframework\zendframework\library\Zend\Form\Factory.php并定义在C:\vendor\doctrine\doctrine-module\src\\ DoctrineModule\Stdlib\Hydrator\DoctrineObject.php第63行

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

我无法使用 Zend\ stdlib\Hydrator\ObjectProperty 因为那我得到

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?

我猜想我需要一个 __ construct()功能。但是我在那里放什么?

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

推荐答案

有人可能会想出一个只有注释的功能,如果存在,同时你可以采用这种方法:

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

这篇关于Zend Framework 2 - 注释形式和Doctrine2 - 可追踪的致命错误 - ObjectManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆