I have the following controller:
namespace Acme\CompanyBundle\Controller;
use Symfony\Component\DependencyInjection\Container;
/**
* Company controller.
*
*/
class CompanyController extends Controller
{
protected $container;
public function __construct(Container $container)
{
$this->container = $container;
}
public function getData()
{
$userObj = $this->container->get('security.context')->getToken()->getUser();
}
}
In my services.yml
file, I have injected Container
class:
parameters:
acme.controller.company.class: Acme\ContainerBundle\Controller\CompanyController
services:
acme.controller.company:
class: %acme.controller.company.class%
arguments: [@service_container]
When loading this controller, I get following error:
Catchable Fatal Error: Argument 1 passed to Acme\CompanyBundle\Controller\CompanyController::__construct() must be an instance of Symfony\Component\DependencyInjection\Container, none given, called in C:\wamp\www\symfony\app\cache\dev\classes.php on line 2785 and defined in C:\wamp\www\symfony\src\Acme\CompanyBundle\Controller\CompanyController.php line ...
As you could see, this is a simple injection of Container
object into a controller but throws nice errors. What is the problem here?
Similar issue is posted in another SO thread here.