我有兩個實體,User和Lesson。Symfony2 - 在錯誤的地方尋找實體類?
用戶是索納塔用戶的擴展,是在
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
Stack Trace
in /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php
at line 233 -+ } // We need to pick the type hint class too if (($paramClass = $param->getClass()) !== null) { $parameterString .= '\' . $paramClass->getName() . ' '; } else if ($param->isArray()) { $parameterString .= 'array '; at ReflectionParameter ->getClass() in /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php at line 233 -+ at ProxyFactory ->_generateMethods (object(ClassMetadata)) in /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php at line 155 -+ at ProxyFactory ->generateProxyClass (object(ClassMetadata), '/home/dan/sites/mysite/app/cache/dev/doctrine/orm/Proxies/CG_LessonBundleEntitySubject.php', '; /** * THIS CLASS WAS GENERATED BY THE DOCTRINE ORM. DO NOT EDIT THIS FILE. */ class extends \ implements \Doctrine\ORM\Proxy\Proxy { private $_entityPersister; private $identifier; public $_isInitialized = false; public function construct($entityPersister, $identifier) { $this->_entityPersister = $entityPersister; $this->_identifier = $identifier; } /** @private */ public function _load() { if (!$this->_isInitialized && $this->_entityPersister) { $this->isInitialized = true; if (method_exists($this, "wakeup")) { // call this after _isInitialized_to avoid infinite recursion // but before loading to emulate what ClassMetadata::newInstance() // provides. $this->__wakeup(); } if ($this->_entityPersister->load($this->_identifier, $this) === null) { throw new \Doctrine\ORM\EntityNotFoundException(); } unset($this->_entityPersister, $this->_identifier); } } /** @private */ public function _isInitialized() { return $this->_isInitialized; } public function sleep() { } public function _clone() { if (!$this->_isInitialized && $this->_entityPersister) { $this->isInitialized = true; $class = $this->_entityPersister->getClassMetadata(); $original = $this->_entityPersister->load($this->_identifier); if ($original === null) { throw new \Doctrine\ORM\EntityNotFoundException(); } foreach ($class->reflFields as $field => $reflProperty) { $reflProperty->setValue($this, $reflProperty->getValue($original)); } unset($this->_entityPersister, $this->_identifier); } } }') in /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php at line 90 -+ at ProxyFactory ->getProxy ('LessonBundle\Entity\Subject', array('id' => '1')) in /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php at line 2576 -+ at UnitOfWork ->createEntity ('LessonBundle\Entity\Lesson', array('id' => '1', 'date' => object(DateTime), 'time' => object(DateTime), 'objective' => 'test', 'created_at' => object(DateTime), 'updated_at' => object(DateTime), 'tutor_id' => '1', 'service_id' => '1', 'trip_id' => '1', 'subject_id' => '1', 'location_id' => '1'), array('deferEagerLoads' => true, 'fetchMode' => array('LessonBundle\Entity\Lesson' => array('tutor' => '2', 'service' => '2', 'trip' => '2', 'subject' => '2')))) in /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php at line 135 -+ at SimpleObjectHydrator ->hydrateRowData (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' => object(ClassMetadata), 'name' => 'time', 'field' => true), 'objective4' => array('class' => object(ClassMetadata), 'name' => 'objective', 'field' => true), 'created_at5' => array('class' => object(ClassMetadata), 'name' => 'created_at', 'field' => true), 'updated_at6' => array('class' => object(ClassMetadata), 'name' => 'updated_at', 'field' => true), 'tutor_id7' => array('name' => 'tutor_id'), 'service_id8' => array('name' => 'service_id'), 'trip_id9' => array('name' => 'trip_id'), 'subject_id10' => array(DEEP NESTED ARRAY), 'location_id11' => array(DEEP NESTED ARRAY)), array()) in /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php at line 50 -+ at SimpleObjectHydrator ->hydrateAllData() in /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php at line 111 -+ at AbstractHydrator ->hydrateAll (object(PDOStatement), object(ResultSetMapping), array('deferEagerLoads' => true)) in /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php at line 848 -+ at BasicEntityPersister ->loadAll (array(), null, null, null) in /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php at line 157 -+ at EntityRepository ->findBy (array()) in /home/dan/sites/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php at line 141 -+ at EntityRepository ->findAll() in /home/dan/sites/mysite/src/LessonBundle/Controller/LessonController.php at line 21 -+ at LessonController ->listAction() at call_user_func_array (array(object(LessonController), 'listAction'), array()) in kernel.root_dir/bootstrap.php.cache at line 1426 -+ at HttpKernel ->handleRaw (object(Request), '1') in kernel.root_dir/bootstrap.php.cache at line 1390 -+ at HttpKernel ->handle (object(Request), '1', true) in kernel.root_dir/bootstrap.php.cache at line 1566 -+ at HttpKernel ->handle (object(Request), '1', true) in kernel.root_dir/bootstrap.php.cache at line 617 -+ at Kernel ->handle (object(Request)) in /home/dan/sites/mysite/web/app_dev.php at line 29 -+
我不知道爲什麼它尋找在LessonBundle,而不是應用程序\索納塔\ UserBundle User類。
任何意見讚賞。
謝謝