aaaa aaaa - 4 years ago 273
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"


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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download