aaaa aaaa - 4 months ago 20
PHP Question

Symfony 2 ServiceNotFoundException

I am trying to use doctrine in my symfony API project, I have this controller but when it is called I get the error "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);
}
}

Answer

Possibly a typo.

Check if the service exist by dumping your container service deifinition via command line as:

 php app/console container:debug

In my case the service is named as doctrine.orm.entity_manager

Comments