Q
Q
Quber2014-11-05 03:03:51
symfony
Quber, 2014-11-05 03:03:51

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

4 answer(s)
M
mind3, 2014-11-05
@Quber

has_role - checks access by the user's role
is_granted - checks permissions to perform an action.

A
Alexander Aksentiev, 2014-11-05
@Sanasol

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

A
Alexander Zelenin, 2014-11-05
@zelenin

role check and permission check.
It's good practice to give access by permissions, not by role. It's more flexible.

G
genby8, 2020-10-08
@genby8

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 question

Ask a Question

731 491 924 answers to any question