我有路线 / track / Johnny + Cash / There + You + Go 我需要路线参数artist_name =“Johnny Cash”,name =“There You Go”(没有加号)
为此,我在MainBundle \ Resources \ config \ services.yml
中添加了监听器services:
app.listener.location:
class: Melofania\MainBundle\LocationListener
scope: request
tags:
- { name: kernel.event_listener, event: kernel.controller }
arguments: []
创建文件MainBundle \ LocationListener.php
namespace Melofania\MainBundle;
use Symfony\Component\HttpKernel\HttpKernel;
class LocationListener {
public function onKernelController($event) {
if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
return;
}
$request = $event->getRequest();
$parameters = $request->attributes->get('_route_params');
foreach($parameters as &$parameter) {
$parameter = str_replace('+', ' ', $parameter);
}
$request->attributes->set('_route_params', $parameters);
}
}
但是控制器中的路由参数没有改变。任何人都可以解释这个错误?谢谢你的回答。