Reputation: 457
I tried to look how i can put a prefix in a path of route.
#routing.yml
app_news:
path: /panel/news
defaults: { _controller: NewsBundle:Default:index }
I have some routes like this, if i want change in the future the name of the path, for example
/admin/news or /control/news
Can i save the prefix in other config yml file and change it when i want?
Upvotes: 2
Views: 633
Reputation: 457
In this case i have some like this
#/app/config/routing.yml
users:
resource: "@UsersBundle/Resources/config/routing.yml"
prefix: /panel/
news:
resource: "@NewsBundle/Resources/config/routing.yml"
prefix: /panel/
Now, after read the answers and see the others ways i put the prefix, i set the prefix in a var
#/app/config/routing.yml
users:
resource: "@UsersBundle/Resources/config/routing.yml"
prefix: %panel_path%
news:
resource: "@NewsBundle/Resources/config/routing.yml"
prefix: %panel_path%
And i set the %panel_path% var value in
#/app/config/config.yml
parameters:
panel_path: /panel
Upvotes: 0
Reputation: 446
Put all of your prefixed routes on the same routing file and then add it to your bundle routing using the resource and the prefix attribute:
applications:
resource: "@NewsBundle/Resources/config/routing_news.yml"
prefix: /panel
Also, if you have your routes on your controller. You can do the same trick using the annotation attribute:
applications:
resource: '@NewsBundle/Controller/NewsController'
type: annotation
prefix: /panel
Syntaxis changes depending on your Symfony version, so I recommend you to visit the Symfony documentation.
Upvotes: 3