在事件侦听器中访问路径路径

时间:2014-10-13 15:51:59

标签: php symfony

ROUTE:

user_lock:
    path:     /user/lock/{id}
    defaults: { _controller: SiteMainBundle:Frontend\Default:userLock }
    methods:  [GET]

如您所知,上面的路由器将创建一个类似htt://mysite.com/app_dev.php/user/lock/66的网址,因此我需要在下面的事件监听器中仅获取/user/lock/66部分内容。我该怎么办?

我试过$request->getBaseUrl()$request->getBasePath()没有给我我想要的东西。

YAML

services:
    kernel.listener.kernel_controller:
        class: Site\MainBundle\EventListener\Controller\KernelController
        tags:
            - { name: kernel.event_listener, event: kernel.controller, method: onKernelController }

<?php

namespace Site\MainBundle\EventListener\Controller;

use Symfony\Component\HttpKernel\Event\FilterControllerEvent;

class KernelController
{
    public function onKernelController(FilterControllerEvent $event)
    {
        $request = $event->getRequest();

        $this->writeLog('ROUTE', $request->attributes->get('_route'));
        $this->writeLog('CONTROLLER', $request->attributes->get('_controller'));
        $this->writeLog('ROUTE PARAMETERS', $request->attributes->get('_route_params'));

        $this->writeLog('ROUTE PATH', ??????????????????????????????);
    }
} 

1 个答案:

答案 0 :(得分:1)

我想,你正在寻找

$request->server->get('PATH_INFO');