如何为我的所有路由添加前缀 [英] How to add a prefix to all my routes

查看:68
本文介绍了如何为我的所有路由添加前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个使用 symfony 1.4 构建的网站,我需要为所有路由实现一个路由前缀.此前缀用于为网站指定两种不同的视图",例如:

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

这两个 URL 呈现相同的模块/操作,但几乎没有具体差异(文本、图像等).因此,www.domain.com/b2b/module1/action1 和 www.domain.com/b2c/module1/action1 必须执行相同的操作/视图,但前缀应在操作或模板中可捕获.

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.

有没有一种方法可以实现这一点,而不必在每个 urlFor/routeFor 调用中硬编码前缀?

Is there a way to implement this without having to hard-code the prefix in every urlFor/routeFor call ?

推荐答案

我找到了一个很好的资源页面,可以满足您的需求:
http://particul.es/blog/index.php?post/How-to-change-backend.php-to-admin-prefix-routes-automatically-symfony
提供多种解决方案来实现您的目标.但是,就个人而言,我认为对您来说最明智的方法是在 .htaccess 中处理此问题.

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.

这篇关于如何为我的所有路由添加前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆