问题
I'm currently working on a website built with symfony 1.4 and I need to implement a route prefix for all the routes. This prefix is used to specify two differents "views" for the website, for exemple :
www.domain.com/b2b : B2B oriented view
www.domain.com/b2c : B2C oriented view
Both of these URLs render the same modules/actions but with little specific differences (textes, images, ...). So, www.domain.com/b2b/module1/action1 and www.domain.com/b2c/module1/action1 must proceed the same action/view but the prefix should be catchable in the action or template.
Is there a way to implement this without having to hard-code the prefix in every urlFor/routeFor call ?
回答1:
I have found a great ressource page for your needs:
http://particul.es/blog/index.php?post/How-to-change-backend.php-to-admin-prefix-routes-automatically-symfony
With many solutions to achieve your goals. But, personnaly, I think that the smartest way for you is to handle this in .htaccess.
回答2:
You could create your own routing classes, which appends the "view" (b2b/b2c) to the route, and parses it when needed.
Create an custom class which inherits from sfRoute
. In your routing.yml
add class: myRouteClassName
to the routes.
来源:https://stackoverflow.com/questions/6841400/how-to-add-a-prefix-to-all-my-routes