I have an action inside my controller class and I want two different routes like below:
/**
* Displays a form to create a new entity.
*
* @Route("/edit/choose/date", name="user_choose_date")
* @Route("/supervisory/choose/date", name="sup_choose_date")
* @Template()
*/
public function chooseDateAction()
{
return array( );
}
The reason for that I would like to give the route access to some users but the user role are different.
Let's say:
User with supervisor
role can access sup_choose_date
User with user
role can access user_choose_date
The question is if it is possible to have two different routes for one action? or I have duplicate the code for different routes ?
Yes, it is possible when using YAML (or XML) routing.
Example:
sup_choose_date:
pattern: /supervisory/choose/date
defaults: { _controller: MyBundle:Default:chooseDate }
user_choose_date:
pattern: /edit/choose/date
defaults: { _controller: MyBundle:Default:chooseDate }
Worked for me!
You must set different names; if not, specify explicitly
I is possible on every kind of format including annotation. It should work as long as you have different name for every route.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With