简体   繁体   中英

Symfony2: Dynamic Routing Prefix

I need to create a dynamic routing scheme, where I am prefixing the routes with a variable that changes.

Here's an example:

Application Base Route: /dashboard/

Scenario A: /client_a/dashboard/
Scenario B: /client_b/dashboard/
Scenario C: /client_c/dashboard/

The idea is to keep the application core code all the same, but allow different clients to be referenced in the route.

What's best practice to set this up? I can add a static prefix in the routing.yml, but unless the ' prefix: /myparameter ' can be set up dynamically, this may not work for me. Primary reason for this is an existing Symfony2 application that is quite complex.

If I am using /{client_name}/dashboard/ , I'll have to change all the paths in the application, since now I have an additional parameter missing in the route. So, I am looking for a solution that allows me to retrofit the existing application without necessarily having to touch the application main code.

Thanks,

JB

@Jakub's comment is essentially correct. However, if, as in my case, an existing Symfony app has to be retrofitted for this new requirement, it is extremely tedious. There is furthermore an issue with the security implementation in Symfony in that Symfony requires static paths for the login, login_check, and logout methods. So, any use of the prefix in those scenarios doesn't seem to be currently supported.

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