如何在Symfony投票者中获取请求参数?
我设置了请求和堆栈参数如何在Symfony投票者中获取请求参数?,symfony,Symfony,我设置了请求和堆栈参数 api.uid_voter: class: SecretBundle\Security\UidVoter arguments: ['@request_stack'] tags: - { name: security.voter } public: false #app/config/security.yml access_control: - { path: ^/secret, roles: [UID] } 下一
api.uid_voter:
class: SecretBundle\Security\UidVoter
arguments: ['@request_stack']
tags:
- { name: security.voter }
public: false
#app/config/security.yml
access_control:
- { path: ^/secret, roles: [UID] }
下一步我试着投票
public function __construct(RequestStack $request_stack)
{
$this->uid = $request_stack->getCurrentRequest()->get('uid');
}
及
在null上调用成员函数get()
但是,如果来自控制器的$this->denyaccessunlessgrated('UID')没有错误,则在创建服务本身时,实际请求不可用。您需要在实际需要时获取uid。比如:
class MyVoter {
private $requestStack;
public function __construct($requestStack) {
$this->requestStack = $requestStack;
}
private function getUid() {
return $this->requestStack->getMasterRequest()->get('uid');
我需要简单地比较url中的UID和令牌中的授权用户ID