支持Zend和多语言支持的路由问题模块化应用
我在Zend-Router上苦苦挣扎。我想在我的网址中链接语言。一切正常,但我的模块化路由。支持Zend和多语言支持的路由问题模块化应用
如果我打电话:http://domain.de/en/index
- 我的IndexController的默认模块的indexAction被执行和翻译。
同样如下: http://domain.de/en/about
所以调用IndexController的aboutAction。
如果我打电话给:http://domain.de/en/forum/index
它应该执行论坛模块的IndexController的indexAction。但事实并非如此。
我的目标是尽可能缩短我的网址,因此它没有“默认”或“索引”。
你能帮我编辑我的routes.xml,所以我得到想要的结果吗?
我routes.xml
<config>
<routes>
<sc1 type="Zend_Controller_Router_Route">
<route>:lang/:@module/:@controller/:@action</route>
<defaults>
<lang>de</lang>
<module>default</module>
<controller>index</controller>
<action>index</action>
</defaults>
</sc1>
<sc2 type="Zend_Controller_Router_Route">
<route>:lang/:@module/:@action</route>
<defaults>
<lang>de</lang>
<module>default</module>
<controller>index</controller>
<action>index</action>
</defaults>
</sc2>
<sc3 type="Zend_Controller_Router_Route">
<route>:lang/:@controller/:@action</route>
<defaults>
<lang>de</lang>
<module>default</module>
<controller>index</controller>
<action>index</action>
</defaults>
</sc3>
<sc4 type="Zend_Controller_Router_Route">
<route>:lang/:@action</route>
<defaults>
<lang>de</lang>
<module>default</module>
<controller>index</controller>
<action>index</action>
</defaults>
</sc4>
</routes>
</config>
你有一个爱迪?
谢谢你在前进, 托比亚斯
我没有太大的Zend的路线,而是看你的代码,你需要一种方法来区分它应该去哪些模块。您已将其设置为所有事件的默认设置。如果它可以像你一样具有动态性,那将是非常好的,但我认为你需要为论坛等设置路由。鉴于Zend需要知道将它发送到哪里。如果你可以弄清楚如何使用:@module变量将它发送到那个模块,那可行,但我不知道/认为这是可能的。
阅读完手册后,我想出了这个结构。您将必须定义您希望它重定向到的每个项目,例如论坛,如下所示。
<config>
<routes>
<language type="Zend_Controller_Router_Route">
<route>:language</route>
<reqs language="[a-z]{2}">
</language>
<index type="Zend_Controller_Router_Route_Static">
<route></route>
<defaults module="default" controller="index" action="index" />
</index>
<about type="Zend_Controller_Router_Route_Static">
<route>about</route>
<defaults module="default" controller="index" action="about" />
</about>
<forums type="Zend_Controller_Router_Route_Static">
<route>forums</route>
<defaults module="forums" controller="index" action="index" />
</forums>
<lang-forums type="Zend_Controller_Router_Route_Chain">
<chain>language, forums</chain>
</lang-forums>
<lang-about type="Zend_Controller_Router_Route_Chain">
<chain>language, about</chain>
</lang-about>
</routes>
</config>
我不是100%地肯定了about
部分,特别是链接,但它搞乱应该给你正确的方法。
EDIT
的下面在生产节拍左正如另一种可能的例子。我想我上面有正确的答案。
看着Zend Routes Manual它是如何设置它很混乱。我也不喜欢在XML格式的工作,我更喜欢在.ini,但这里是一个“伪小样”它应该如何工作(未经测试,因为这将是很难进行测试):
lang.index.type = "Zend_Controller_Router_Route"
lang.index.route = ":language"
lang.index.defaults.controller = index
lang.index.defaults.action = index
lang.forums.index.type = "Zend_Controller_Router_Route_Static"
lang.forums.index.route = "forums"
lang.forums.index.controller = forums
lang.forums.index.action = index
lang.forums.register.type = "Zend_Controller_Router_Route_Static"
lang.forums.register.route = "forums/register"
lang.forums.register.controller = forums
lang.forums.register.action = register
lang.forums.login.type = "Zend_Controller_Router_Route_Static"
lang.forums.login.route = "forums/login"
lang.forums.login.controller = forums
lang.forums.login.action = login
lang.forums.view.type = "Zend_Controller_Router_Route_Static"
lang.forums.view.route = "forums/thread/:slug"
lang.forums.view.controller = forums
lang.forums.view.action = view
lang.other.index.type = "Zend_Controller_Router_Route_Static"
lang.other.index.route = "other"
lang.other.index.controller = other
lang.other.index.action = index
lang.other.view.type = "Zend_Controller_Router_Route_Static"
lang.other.view.route = "other/:slug"
lang.other.view.controller = other
lang.other.view.action = view
希望能让你以正确的思路来推动你需要做的事情。如果有人知道如何动态地做,我完全有兴趣!我将研究xml方法,看看我是否无法解释如何从糟糕的文档中正确地做到这一点。
但是,还有没有更好的办法比手动声明一切? 我的意思是模块化路线工作得很好。只有当我想要链接语言时,我的模块才不再可用。 – 2010-09-22 19:32:33
不是我所知道的。如果你能测试/发现它,我会有兴趣知道。我能看到的唯一方法是在声明中使用变量IE:' @:module '但我非常怀疑这是可能的。 –
2010-09-22 19:34:51