开发者

How to add a prefix to all my routes

开发者 https://www.devze.com 2023-03-23 09:15 出处:网络
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 web

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 ?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消