php - Symfony 2 ServiceNotFoundException

标签 php symfony doctrine-orm namespaces

我试图在我的 symfony API 项目中使用学说,我有这个 Controller ,但是当它被调用时,我收到错误“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);
    }
}

最佳答案

可能是笔误。

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

 php app/console container:debug

在我的例子中,该服务被命名为 doctrine.orm.entity_manager

关于php - Symfony 2 ServiceNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27967312/

相关文章:

php - Symfony - 从未导入注释

php - 教义不在查询中

php - 如何使用 ZendOpCache 作为 Doctrine2 缓存?

php - 使用 xml-rpc 向自定义字段添加值

php - mysql_fetch_array 返回重复数据

php - 无法使用 FOSRestBundle

php - <img src="{{ asset 上缺少资源

PHP-getimagesize 函数

php - 从twig中的php获取数据时的if语句

symfony - 如何提高 symfony 中大数据导入的性能?