Symfony 2 ServiceNotFoundException

aaa*_*aaa 1 php namespaces symfony doctrine-orm

我试图在我的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);
    }
}
Run Code Online (Sandbox Code Playgroud)

Mat*_*teo 5

可能是拼写错误.

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

 php app/console container:debug
Run Code Online (Sandbox Code Playgroud)

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