Answer the question
In order to leave comments, you need to log in
What is the difference between is_granted() and has_role() in Symfony 2 framework?
Actually a subject. What is the difference between is_granted() and has_role() in Symfony 2 framework? For example, here symfony.com/doc/current/bundles/SensioFrameworkExt...
Here is an example from the SensioFrameworkExtraBundle documentation :
/**
* @Security("has_role('ROLE_ADMIN') and is_granted('POST_SHOW', post)")
*/
public function showAction(Post $post)
{
// somethings
}
Answer the question
In order to leave comments, you need to log in
has_role - checks access by the user's role
is_granted - checks permissions to perform an action.
Not a connoisseur of the symphony, but if you try to understand.
is granted have access to any function.
has role Belonging to a group.
Those. admin group does not necessarily have post_show access
role check and permission check.
It's good practice to give access by permissions, not by role. It's more flexible.
Here is a link to the documentation . The idea is that the author of an entity ( news or comment or something else) can edit it without being an editor / moderator, etc. To do this, the symphony has a "vote" where the rights to act with the entity are checked.
Note: the subject on which the rights are checked is not necessarily an entity.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question