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', ??????????????????????????????);
}
}
答案 0 :(得分:1)
我想,你正在寻找
$request->server->get('PATH_INFO');