Answer the question
In order to leave comments, you need to log in
Symfony voters, why does passing $request_stack cause an error?
I'm trying to figure out Voters and check the user ID to match the $uid from the request. It seems logical to pass the $request_stack to the service But there is a problem
# app/config/security.yml
* If I specify the water attribute in the access_control, I get the error "Trying to get property of non-object" when I try to get the $uid request parameter $request_stack ->getCurrentRequest()->get('uid');
access_control:
- { path: ^/secret, roles: [UID] }
api.uid_voter:
class: SecretBundle\Security\UidVoter
arguments: ['@request_stack']
tags:
- { name: security.voter }
public: false
public function __construct(RequestStack $request_stack)
{
$request = $request_stack->getCurrentRequest();
if ($request) {
$this->uid = $request->get('uid');
}
}
Answer the question
In order to leave comments, you need to log in
1. You need a method getMasterRequest()
2. You need to receive the object $request
during the execution of the service methods, and not in the constructor
3. You if ($request) {
still have to wrap it in, because, for example, there will be no request in the console
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question