K
K
kapai692014-11-11 18:55:11
symfony
kapai69, 2014-11-11 18:55:11

Symfony2 how to pass a container from a controller?

Can't pass container to controller

//...
use Symfony\Component\DependencyInjection\ContainerInterface;

class TestController extends Controller
{
    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }
}

Service announcement
parameters:
    # ...
    test.class: Test\TestBundle\Controller\TestController

services:
    test:
        class:     "%test.class%"
        arguments: ["@service_container"]

The instance is not created at all, writes the argument in the constructor is passed.
Where is the mistake?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BoShurik, 2014-11-11
@kapai69

symfony.com/doc/current/cookbook/controller/servic...
In the route settings, replace
on the
defaults: { _controller: test:indexAction }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question