【问题标题】:Symfony2 - Looking for entity class in wrong place?Symfony2 - 在错误的地方寻找实体类?
【发布时间】:2013-01-25 03:57:22
【问题描述】:

我有两个实体,用户和课程。

User 是 Sonata User 的扩展,在

Application\Sonata\UserBundle\Entity\User

课程在我自己的捆绑包“LessonBundle”中

每节课都归用户所有,在现场导师下:

class Lesson
{
    /**
     * @ORM\ManyToOne(targetEntity="Application\Sonata\UserBundle\Entity\User", inversedBy="lessons")
     * @ORM\JoinColumn(name="tutor_id", referencedColumnName="id")
     */
    protected $tutor;

/**
     * Set tutor
     *
     * @param \Application\Sonata\UserBundle\Entity\User $tutor
     * @return Lesson
     */
    public function setTutor(\Application\Sonata\UserBundle\Entity\User $tutor = null)
    {
        $this->tutor = $tutor;

        return $this;
    }

    /**
     * Get tutor
     *
     * @return \Application\Sonata\UserBundle\Entity\User 
     */
    public function getTutor()
    {
        return $this->tutor;
    }
}

我设置了一个表单,可以成功为用户添加课程,但是当我尝试访问课程列表时:

$repository = $this->getDoctrine()
                        ->getRepository('LessonBundle:Lesson');

//Problem is triggered here
$lessons = $repository->findAll();

我收到以下错误:

Class LessonBundle\Entity\User does not exist

堆栈跟踪

in /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php

在第 233 行 -+ } // 我们也需要选择类型提示类 if (($paramClass = $param->getClass()) !== null) { $parameterString .= '\' 。 $paramClass->getName() 。 ' '; } else if ($param->isArray()) { $parameterString .= '数组'; 在反射参数->getClass() 在 /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php 在第 233 行 -+ 在 ProxyFactory ->_generateMethods (object(ClassMetadata)) 在 /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php 在第 155 行 -+ 在 ProxyFactory ->generateProxyClass (object(ClassMetadata), '/home/dan/sites/mysite/app/cache/dev/doctrine/orm/Proxies/CG_LessonBundleEntitySubject. php', '; /** * 这个类是由 教义 ORM。不要编辑此文件。 */ 类扩展 \ 实现 \Doctrine\ORM\Proxy\Proxy { 私有 $_entityPersister;私人 $ 标识符;公共 $_isInitialized = 错误的;公共函数 construct($entityPersister, $identifier) { $this->_entityPersister = $entityPersister; $this->_identifier = $标识符; } /** @private */ public function _load() { if (!$this->_isInitialized && $this->_entityPersister) { $this->isInitialized = true; if (method_exists($this, "wakeup")) { // 在 _isInitialized_ 之后调用它以避免无限递归 // 但在加载之前模拟什么 ClassMetadata::newInstance() // 提供。 $this->__wakeup(); } 如果 ($this->_entityPersister->load($this->_identifier, $this) === null) { 抛出新的 \Doctrine\ORM\EntityNotFoundException(); } 未设置($this->_entityPersister,$this->_identifier); } } /** @私人的 */ public function _isInitialized() { return $this->_isInitialized; } 公共函数 sleep() { } 公共函数 _clone() { 如果 (!$this->_isInitialized && $this->_entityPersister) { $this->isInitialized = true; 1234562 美元 = $this->_entityPersister->getClassMetadata(); $原始= $this->_entityPersister->load($this->_identifier);如果($原始=== null) { 抛出新的 \Doctrine\ORM\EntityNotFoundException(); } foreach ($class->reflFields as $field => $reflProperty) { $reflProperty->setValue($this, $reflProperty->getValue($original)); } 未设置($this->_entityPersister,$this->_identifier); } } }') 在 /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php 在第 90 行 -+ 在 ProxyFactory ->getProxy ('LessonBundle\Entity\Subject', array('id' => '1')) 在 /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php 在第 2576 行 -+ 在 UnitOfWork ->createEntity ('LessonBundle\Entity\Lesson', array('id' => '1', 'date' => object(DateTime), 'time' => 对象(日期时间),'objective' => 'test','created_at' => 对象(日期时间),'updated_at' => 对象(日期时间),'tutor_id' => '1', 'service_id' => '1', 'trip_id' => '1', 'subject_id' => '1', 'location_id' => '1'), array('deferEagerLoads' => true, 'fetchMode' => 数组('LessonBundle\Entity\Lesson' => 数组('tutor' => '2', 'service' => '2', '旅行' => '2', '主题' => '2')))) 在 /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php 在第 135 行 -+ 在 SimpleObjectHydrator -> hydraRowData (array('id1' => '1', 'date2' => '2013-02-09', 'time3' => '00:00:00', 'objective4' => 'test', 'created_at5' => '2013-02-09 12:19:27', 'updated_at6' => '2013-02-09 12:19:27', 'tutor_id7' => '1', 'service_id8' => '1', 'trip_id9' => '1', 'subject_id10' => '1', 'location_id11' => '1'), array('id1' => array('class' => object(ClassMetadata), 'name' => 'id', 'field' => true), 'date2' => array('class' => object(ClassMetadata), 'name' => 'date', 'field' => true), 'time3' => array('class' => 对象(类元数据),“名称”=>“时间”,“字段”=>真), 'objective4' => 数组('class' => object(ClassMetadata), 'name' => 'objective', 'field' => true), 'created_at5' => array('class' => 对象(ClassMetadata),'name' => 'created_at','field' => true), 'updated_at6' => 数组('class' => object(ClassMetadata), 'name' => 'updated_at', 'field' => true), 'tutor_id7' => array('name' => 'tutor_id'), 'service_id8' => 数组('name' => 'service_id'), 'trip_id9' => 数组('name' => 'trip_id'),'subject_id10' => array(深嵌套阵列), 'location_id11' => array(深嵌套 数组)), 数组()) 在 /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php 在第 50 行 -+ 在 SimpleObjectHydrator -> hydrateAllData () 在 /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php 在第 111 行 -+ 在 AbstractHydrator ->hydrateAll (object(PDOStatement), object(ResultSetMapping), array('deferEagerLoads' => true)) 在 /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php 在第 848 行 -+ 在 BasicEntityPersister ->loadAll (array(), null, null, null) 在 /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php 在第 157 行 -+ 在 EntityRepository ->findBy (array()) 在 /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php 在第 141 行 -+ 在 EntityRepository ->findAll () 在 /home/dan/sites/mysite/src/LessonBundle/Controller/LessonController.php 在第 21 行 -+ 在 LessonController ->listAction () 在 call_user_func_array (array(object(LessonController), 'listAction'), array()) 在 kernel.root_dir/bootstrap.php.cache 第 1426 行 -+ 在 HttpKernel ->handleRaw (object(Request), '1') 在 kernel.root_dir/bootstrap.php.cache 第 1390 行 -+ 在 HttpKernel -> 句柄(对象(请求),'1',真) 在 kernel.root_dir/bootstrap.php.cache 第 1566 行 -+ 在 HttpKernel -> 句柄(对象(请求),'1',真) 在 kernel.root_dir/bootstrap.php.cache 第 617 行 -+ 在内核->句柄(对象(请求)) 在 /home/dan/sites/mysite/web/app_dev.php 第 29 行 -+

我不确定为什么它在 LessonBundle 中寻找 User 类而不是 Application\Sonata\UserBundle。

任何建议表示赞赏。

谢谢

【问题讨论】:

    标签: php symfony doctrine-orm entity


    【解决方案1】:

    找到了。在一个完全不同的类中的错误位置引用了该类!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-01
      相关资源
      最近更新 更多