简体   繁体   中英

Doctrine+Symfony searching for repository in wrong namespace?

first to say I'm really new to both Symfony and Doctrine and am trying really hard to learn it. I found this tutorial http://tutorial.symblog.co.uk/ which guides you through making your own blog in it. The problem is, it was designed for Symfony 2.0 and I'm using 2.1.5. So along the way I had to fix quite a few issues that occured due to changes introduced in both Symfony and Doctrine.

However, this problem is the one I just can't seem to solve the right way. Its really short chapter, 10-15 lines of code total:

http://tutorial.symblog.co.uk/docs/customising-the-view-more-with-twig.html#recent-comments

Its actually only 1 line of code that bugs me! I have a PageController with an action function inside it:

public function sidebarAction()
{
    $em = $this->getDoctrine()->getEntityManager;

    $blogRep = $em->getRepository('BloggerBlogBundle:Blog');

    //........ stuff here

    $em->getRepository('BloggerBlogBundle:Comment') <--------------- THIS
}

The damn thing just doesn't seem to work! I get the error:

Fatal error: Class 'Blogger\BlogBundle\Entity\CommentRepository' not found in /home/igor/Documents/www/igor/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php on line 689

Key thing! : Class 'Blogger....**Entity**

It searches in Entity !

My Repositories are stored in Blogger\\BlogBundle\\Repository namespace! And the weirdest thing is, it finds 'BloggerBlogBundle:Blog' repository without problems, but doesn't find Comment!

Both reside in same folder (Bundles\\Blogger\\BlogBundle\\Repository) and both are declared exactly the same way:

CommentRepository:

namespace Blogger\BlogBundle\Repository;

class CommentRepository extends EntityRepository

BlogRepository:

namespace Blogger\BlogBundle\Repository;

class BlogRepository extends EntityRepository

How I managed to make it work

I moved CommentRepository file to "Entity" directory and changed it's namespace to Blogger\\BlogBundle\\Entity. It works perfectly then. No problems at all. But that way I'm stuck with repositories scattered through dirs and namespaces......

Why does Doctrine find Blog repo and not Comment repo in Blogger\\BlogBundle\\Repository ?

您的Blog实体是否具有@ ORM /存储库注释,而您的Comment实体没有?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM