I'm developing a new symfony project and I implemented and custom voter. In a controller I can call the voters through $this->isGranted('view',$team)
, but for this, I need a team-object. When I want to display a team, it is no problem.
But now I have a base-template with only a top-menu. I only want to display the "Team"-Button, when $this->isGranted('view',$team)
returns true, but in this template I never show any teams, so I don't have a team-object, which I can pass through this function. The first twig template is even a overview of the project.
How can I do this? Should I pass a blank team-object to the base-template? Can anyone help me?
Asked
Active
Viewed 536 times
0

Brian Tompsett - 汤莱恩
- 5,753
- 72
- 57
- 129

user3296316
- 127
- 2
- 3
- 16
-
1Are you able to do this role based instead of a voter on a team object? Since you aren't basing the decision on the team object anyway – JimL Nov 19 '16 at 15:10
1 Answers
0
You should not rely on voter which is related to specific object. I suppose that teams can be shown by logged users (or something like this). So you should check if user is logged what you can do in Symfony by $this->isGranted('IS_AUTHENTICATED_FULLY')
or base on the other state (new role) for example TEAM_VIEWER
but remember that you have to add this role for these users.

Michal S.
- 450
- 3
- 15