Reputation: 12461
I am making services and want to pass 'container' as argument. because I want to use like this
$user = $this->container->get('security.context')->getToken()->getUser();
my Acme/MemberBundle/Resouces/confit/services.xml is like this below.
<services>
<service id="acme.memberbundle.calendar_listener" class="Acme\MemberBundle\EventListener\CalendarEventListener">
<argument type="service" id="container" />
<tag name="kernel.event_listener" event="calendar.load_events" method="loadEvents" />
</service>
</services>
but it says 'The service "acme.memberbundle.calendar_listener" has a dependency on a non-existent service "container"'.
How can I pass my container to services?
this problem is related How to get userid from eventlistener which are called from AJAX
Upvotes: 3
Views: 3219
Reputation: 8645
The container is registered as the service called "service_container", so you must pass "service_container" and not just "container":
<argument type="service" id="service_container" />
This is why currently Symfony doesn't understand what is the service "container" because there is no one registered with this name !
Upvotes: 4