Symfony2 - 在错误的地方寻找实体类?

时间:2013-02-09 13:18:50

标签: php symfony doctrine-orm entity

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

用户是Sonata用户的扩展,位于

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()。 ' &#39 ;;                               } else if($ param-> isArray()){                                   $ parameterString。=' array&#39 ;;       在ReflectionParameter - > 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&#39 ;,   &#39 ;; / ** *此类由THE生成   DOCTRINE ORM。请勿编辑此文件。 * /类扩展   \ implements \ Doctrine \ ORM \ Proxy \ Proxy {private   $ _entityPersister; private $ 标识符; public $ _isInitialized =   假; public function 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-> _entityPersister-> load($ this-> _identifier,$ this)=== null){   抛出\ \ Doctrine \ ORM \ EntityNotFoundException(); }   未设置($ this-> _entityPersister,$ this-> _identifier); } } /** @私人的   * / public function _ isInitialized(){return $ this-> _isInitialized ;公共函数 sleep(){    public function _ clone(){if   (!$ this-> _isInitialized && $ this-> _entityPersister){   $ this-> isInitialized = true; $ class =   $这 - > _entityPersister-> getClassMetadata(); $ original =   $这 - > _entityPersister->负载($这 - > _identifier); if($ original ===   null){throw new \ 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',数组(' id' =>' 1'))       在/home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php   在第2576行 - +       在UnitOfWork - > createEntity(' LessonBundle \ Entity \ Lesson',array(' id' =>' 1',' date' =>对象(日期时间),'时间' =>   对象(日期时间),'目标' => ' test',' created_at' =>   object(DateTime),' updated_at' =>对象(日期时间),' tutor_id' => ' 1&#39 ;,   '的service_id' => ' 1',' trip_id' => ' 1',' subject_id' => ' 1&#39 ;,   ' LOCATION_ID' => ' 1'),数组(' 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 - > hydrateRowData(数组(' id1' =>' 1',' date2' =>' 2013-02-09&# 39;,' 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&#39 ;,   ' trip_id9' => ' 1',' subject_id10' => ' 1',' location_id11' => ' 1&#39),   数组(' id1' =>数组('类' =>对象(ClassMetadata),' name' =>' id' ,   '字段' =>是的,' date2' =>数组(' class' =>对象(ClassMetadata),   '名称' => ' date',' field' =>是的,' time3' =>数组(' class' =>   对象(ClassMetadata),' name' => ' time',' field' =>真正),   ' objective4' =>数组('类' =>对象(ClassMetadata),' name' =>   ' objective',' field' =>是的,' created_at5' =>数组(' class' =>   对象(ClassMetadata),' name' => ' created_at',' field' =>真正),   ' updated_at6' =>数组('类' =>对象(ClassMetadata),' name' =>   ' updated_at',' field' =>是的,' tutor_id7' =>数组('名称' =>   ' tutor_id'),' service_id8' =>数组('名称' =>' service_id'),   ' trip_id9' =>数组('名称' =>' trip_id'),' subject_id10' =>   数组( DEEP NESTED ARRAY ),' location_id11' =>数组( DEEP NESTED   ARRAY )),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(对象(PDOStatement),对象(ResultSetMapping),数组(' 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()       at call_user_func_array(array(object(LessonController),' listAction'),array())       在kernel.root_dir / bootstrap.php.cache第1426行 - +       在HttpKernel - > handleRaw(对象(请求),' 1')       在kernel.root_dir / bootstrap.php.cache第1390行 - +       在HttpKernel - >句柄(对象(请求),' 1',true)       在kernel.root_dir / bootstrap.php.cache第1566行 - +       在HttpKernel - >句柄(对象(请求),' 1',true)       在kernel.root_dir / bootstrap.php.cache第617行 - +       在内核 - >句柄(对象(请求))       在/home/dan/sites/mysite/web/app_dev.php第29行 - +

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

任何建议表示赞赏。

由于

1 个答案:

答案 0 :(得分:0)

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