简体   繁体   中英

Conditionating the routing on Symfony2

Hello I need make some conditions for the all the routes that are on my routing. In a little explication I have a DB that contains users and profiles or roles like you wanna to tell that. on this DB I have too a collection of routes that each profile or role can use or access. I need that before the routing load the controller, I can review if the user have the necesary profile for access to this route.

Notes:

I am using Propel 1.2.* with Symfony2.4

The query that i am using for that is the next:

$permisos = MenuQuery::create()
            ->useAccesoMenuQuery()
            ->usePerfilQuery()
            ->usePerfilUsuarioQuery()
            ->filterByUsuarioId($usuario->getId())
            ->endUse()
            ->endUse()
            ->endUse()
            ->groupBy('menu.id')
            ->find();

The relation between the tables is that:

(FK = ID)User 1-----> ∞ User_profile ∞ <-----1 profile(FK = ID)

I wait that someone here can help me with that I need solve that...

Really Thank you.

Symfony 2 has it's own logic for authentication as well as authorization. You shoud take a look at the security part of the Symfony documentation. If all you need is just checking roles against routes it's all there.
The FOS UserBundle might interest you as it provides additional features recommended by the symfony documentation itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM