This course is archived!
08.
The new Voter Class
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This course is archived!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
10 Comments
Could have sense to put role name in a const inside UserVoter?
So in controller we can write $this->isGranted(UserVoter::USER_VIEW, $user);
Yea, I think this is a great idea actually! You won't be able to use the constant in Twig, but you can use it everywhere else, and it's also documented (via being present as a constant).
Thanks for the feedback :)
Thanks again for that awesome tutorial! One question:
I want to have the profile url directly after the main url of the site: site.com/publicUsername
The solution I came up with is:
MainController.php
But... EXPLOSION!
Now if I try to access site.com/register of course it says that AppBundle\Entity\User object not found instead of using the route for user_register.
I can't find any way to "prioritize" the routes, what would you suggest?
How can I have the profiles directly accessible after the site url? www.site.com/publicUsername
Hey Mike P.!
The only way I know to prioritize urls is to define them first, you would have to put all your routes before
If you are going that way, would be better to use a YML format, so you can prioritize them easier.
UPDATE
I just found the "ChainRouter", I've never used it, but look's like it might help you achieving your goal
https://symfony.com/doc/current/cmf/components/routing/chain.html
Cheers!
Thanks Diego, I want to share the solution:
Tt seems that "define them first" was the right track, but instead of changing the order of the controller action, I defined it as last entry in the routing.yml like proposed here: https://stackoverflow.com/q...
Is there a way to do a "allowUnlessDenied" test rather than isGranted?
I have a case where I'd like to allow users access unless they are specifically denied by a voter.
Hey Geoff Maddock
I think you can just invert the logic when checking for denied access role
Cheers!
If I add a Voter for the user view action, do I see it right that the @SECURITY annotation of the controller action is no longer necessary?
(/**
* @Security("is_granted('ROLE_USER)
*/)
Yo Mike P.!
Whether you've created a custom voter or not.. you still need to call either the "is granted" function somewhere: either in the
@Securityannotation or in your controller (via$this->denyAccessUnlessGranted()or$this->isGranted()). So, it depends on what you mean by "add a Voter for the user view action". Are you calling isGranted (in one of these forms) in that action? If you are not, then the security system (and your voter) are never called.Cheers!
"Houston: no signs of life"
Start the conversation!