2015-01-15 62 views
2

我想在我的symfony API項目中使用的學說,我有這樣的控制器,但是當它被稱爲我的錯誤「ServiceNotFoundException的」Symfony的2 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

嘗試通過命令行'傾銷您的集裝箱服務deifinition PHP的應用程序/控制檯容器:調試'在我的情況下,該服務命名爲'doctrine.orm.entity_manager' – Matteo 2015-01-15 15:52:39

+0

啊,這工作。謝謝 – aaaa 2015-01-15 15:59:55

+1

好吧,我發表我的評論作爲答案,所以你可以關閉這個問題 – Matteo 2015-01-15 16:02:17

回答

5

可能是一個錯字。

檢查服務是否被通過命令行傾銷的集裝箱服務deifinition存在爲:

php app/console container:debug 

在我的情況下,服務被命名爲doctrine.orm.entity_manager

+0

@aaaa請考慮upvote我的答案,如果你覺得它有用 – Matteo 2015-01-22 08:31:13