Q
Q
Quber2014-10-25 04:11:35
PHP
Quber, 2014-10-25 04:11:35

Why does $request->get('_route') return null in Symfony 2?

Applied the following listener

<?php
namespace Acme\HelloBundle\EventListener;

use Symfony\Component\HttpKernel\Event\GetResponseEvent;

class AddressListener
{
    public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        $routeName = $request->get('_route');
        var_dump($routeName);
    }
}

I have about 10 routes used in the project. var_dump shows normally the names of all routes, except for one. It comes out null for some reason, although the route itself is processed normally, as expected. What could be the problem?
The route itself
address:
    path: /address/
    defaults: { _controller: AcmeHelloBundle:Address:index }
    requirements:
        _method: GET

Listener Service
kernel.listener.address:
    class: Acme\HelloBundle\EventListener\AddressListener
    tags:
        - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }

I'm using Symfony 2.5

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question