Symfony 2 ServiceNotFoundException

时间:2015-01-15 15:45:52

标签: php symfony doctrine-orm namespaces

我试图在我的symfony API项目中使用doctrine,我有这个控制器,但是当它被调用时我得到了错误" ServiceNotFoundException"

<?php

namespace Cogc\EnquirerAPIBundle\Controller;

use FOS\RestBundle\Controller\FOSRestController;
use Doctrine;

class PageController extends FOSRestController
{
    public function getPageAction($id)
    {
        return $this->container->get('doctrine.entity_manager')->getRepository('Page')->find($id);
    }
}

1 个答案:

答案 0 :(得分:5)

可能是拼写错误。

通过命令行转储容器服务deifinition来检查服务是否存在:

 php app/console container:debug

在我的情况下,该服务被命名为doctrine.orm.entity_manager