Answer the question
In order to leave comments, you need to log in
How to make Symfony 2.6 ACL + menu generation for set permissions?
I'm using Symfony 2.6.8
I need to use something from the big Symfony box for the admin area of my big project.
It is necessary to make sure that, in accordance with the granted rights to certain pages/sections of the admin panel for a certain user (user groups, user roles), a menu is generated from what is available to him, and also, in case of accessing a page that does not have rights - he was not allowed to do this (for example, it is not in the menu, but he went through the URL).
For the sake of an example, please look at my implementation of this in one of my projects on Kohana 3.3 (all my own, but here I would like to get something out of the box):
So, for example, in the table, on the left we see sections and pages. At the top we see the names of the roles. Checkboxes - access.
You can also see confirmation of this in the header - sections, in the left sidebar - section pages (and breadcrumbs).
Answer the question
In order to leave comments, you need to log in
The question is quite general ...
It has already been answered here .
But... The solution to this problem is several and depends partly on what you have in your dependencies.
As I understand it, it's definitely not a sonata. What does the menu generate for you? Knp or yourself?
ACL pure box?
Option one. Docrine filters . We hang a listener on all objects and include a good acl injection in sql. The plus is obvious - the entire selection of objects of interest to us will be in one service (class). Cons - will work at a lower level.
This will kill a bunch of rabbits at once. Views will not draw "forbidden" links, objects, pages will not even show them, simply because they will not be - they will not come from the entity manager. As far as controllers and method access are concerned, SensioLab provides excellent annotations
. Option Two.
Forget what $this->getDoctrine()->getManager(); in the controller. We take it to services and use $this->get('app.shop.manager)->getProducts(); . We extend all managers from the abstract class where acl is implemented.
Option three. We violate all the principles of KISS and DRY and shit code in every class related to the ACL.
But anyway, read this .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question