0

In my Synfony2 wep application, there is two different role that the same user can have. He can whether be an employee or a boss. So, I want to have a switch button the change role so the user have a different view on data. For example, has a Boss the user would see the progress of the work in a project and as a Employee he would see the work to be done from each member of the team in the same project. So basically, the boss would have privilege on some action and the employee on some others.

How should I do the switch between the roles? I was planning to have two different url for each roles /boss/todesand employee/todos. In some case, I would use the same twigs template (e.g. the listing of the todos). How do I do when I need to generate a URL such as /boss/todos/{id} by always specifying the same route_name path('todo_show', {'id': id}).

I think it is pretty similar to the _locale parameter. Is it possible to create a custom parameter similar to _locale in Symfony 2.3?

Thanks in advance !

Frank6
  • 1,193
  • 1
  • 11
  • 23

2 Answers2

0

IMO you think too complex. Create one route for both users, say /todo/{id} which will redirect user based on their role to the user specific route /boss/todo/{id} or /employee/todo/{id}.

sickelap
  • 897
  • 11
  • 21
0

setting a default parameter in your routing config file is not enought?

todo_show:
    pattern:  /{_user}/todos/{id}
    defaults: { _controller: YourAppBundle:Default:getTodos, _user: boss }
    requirements:
        _user: boss|employee       
    methods:  [GET]

and then:

path('todo_show', {'id': id, '_user': 'employee'}); // for boss there is no need to specify _user
vincenzodb
  • 171
  • 1
  • 11
  • That way Frank6 will have to add _user parameter into template if user is not boss. I think he wants automatic user selection based on currently logged-in user. Frank6 am I right? – sickelap Oct 03 '13 at 06:18
  • ok but for N roles = 1 parameter with N accepted values or N routes I guess – vincenzodb Oct 03 '13 at 06:56