I want to pass an instance of EntityManager to the constructor of my controller using this code:
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Doctrine\ORM\EntityManager;
class UserController extends Controller
{
public function __construct( EntityManager $entityManager )
{
}
}
I am doing a constructor injection by putting the parameters in the service.yml file:
parameters:
services:
app.user_controller:
class: AppBundle\Controller\UserController
arguments: ['@doctrine.orm.entity_manager']
service.yml is included in config.yml and when I run
php bin / console debug: container app.user_controller
I get:
Information for Service "app.user_controller"
=============================================
------------------ -------------------------------------
Option Value
------------------ -------------------------------------
Service ID app.user_controller
Class AppBundle\Controller\UserController
Tags -
Public yes
Synthetic no
Lazy no
Shared yes
Abstract no
Autowired no
Autowiring Types -
------------------ -------------------------------------
However, by invoking a route that maps to my controller, I get:
FatalThrowableError in UserController.php line 17: Type error: Argument 1 went to AppBundle \ Controller \ UserController :: __ construct () must be an instance of Doctrine \ ORM \ EntityManager, not specified, called / home / michel / Documents / Terminfinder / vendor / symfony / symfony / src / Symfony / Component / HttpKernel / Controller / ControllerResolver.php on line 202
I can’t understand why EntityManager is not being entered?