I am using a symfony controller as a service.But when I call doctrine manager in the controller it gives the error FatalErrorException: Error: Call to a member function has() on a non-object.
Here is my controller:
namespace Acme\StoreBundle\Controller; use Doctrine\ORM\EntityManager; class ServiceController extends Controller { /** * * @var EntityManager */ protected $em; public function __construct(EntityManager $em) { $this->em = $em; } }
and my services.yml is like:
services:
service_controller:
class: Acme\StoreBundle\Controller\ServiceController
arguments: ["@doctrine.orm.entity_manager"]
I am calling the entity manager in an other controller which DbController:
<?php
public function users()
{
$query = $this->em->createQuery('select u from AcmeStoreBundle:User u');
$user = $query->getResult();
}