我有这个事件监听器类:
<?php
namespace Vdv\TimesheetsBundle\Event;
use Oneup\UploaderBundle\Event\PostPersistEvent;
use Symfony\Component\HttpFoundation\Request;
class UploadListener {
public function __construct($doctrine) {
$this->doctrine = $doctrine;
}
public function onUpload(PostPersistEvent $event) {
$request = $event->getRequest();
}
}
和这个网址:
http://localhost/vdvinfra/web/app_dev.php/timesheet/add/1/252
我想从该网址获取一些参数(id's)。 我怎样才能在事件监听器类中获取它。 当我var_dump this ...
时,变量$ _GET为空谢谢!
答案 0 :(得分:3)
您可以将@request_stack
注入您的事件监听器,就像您已经使用了doctrine一样:
public function __construct($doctrine, $requestStack) {
$this->doctrine = $doctrine;
$this->request = $requestStack->getCurrentRequest();
// access the parameters like this:
$allParams = $this->request->attributes->all();
$someParam = $this->request->attributes->get('parameter_name');
}