Q
Q
Quber2014-11-06 08:08:31
symfony
Quber, 2014-11-06 08:08:31

How to assign a user access rights to a function in symfony 2 (is_granted)?

Took the function, according to documentation symfony.com/doc/current/bundles/SensioFrameworkExt...

/**
 * @Security("is_granted('POST_SHOW', post)")
 */
public function showAction(Post $post)
{
    // somethings
}

I can’t figure out how to give the user these same POST_SHOW rights so that he can use the function below. Help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
neolink, 2014-11-06
@Quber

There are at least 2 options here:
You can use Acl - symfony.com/doc/current/cookbook/security/acl.html
Or create your own Voter - symfony.com/doc/current/cookbook/security/voters_d...
Acl is a universal option , added permission (in your case it will be view) and all
Voter can implement more complex checks, for example, allow COMMENT_EDIT only to its author for 5 minutes. Or universal - Make an interface

interface OwnerableInterface {
    /**
     *  return User
     */
    public function getOwner();
}

and in water simply by condition
to allow editing these objects

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question