我是Zend框架的新手,我正在使用.ini文件在我的应用程序中添加路由。
我有两条不同模块的路线
resources.router.routes.news_view.type = "Zend_Controller_Router_Route_Regex"
resources.router.routes.news_view.route = "([0-9\-]+)/([a-zA-Z0-9\-]+)\.html"
resources.router.routes.news_view.defaults.module = "news"
resources.router.routes.news_view.defaults.controller = "index"
resources.router.routes.news_view.defaults.action = "view"
resources.router.routes.news_view.map.1 = "date"
resources.router.routes.news_view.map.2 = "title"
resources.router.routes.edu_view.type = "Zend_Controller_Router_Route_Regex"
resources.router.routes.edu_view.route = "([0-9\-]+)/([a-zA-Z0-9\-]+)\.html"
resources.router.routes.edu_view.defaults.module = "education"
resources.router.routes.edu_view.defaults.controller = "index"
resources.router.routes.edu_view.defaults.action = "article"
resources.router.routes.edu_view.map.1 = "date"
resources.router.routes.edu_view.map.2 = "title"
网址模式就像
http://news.mysite.com/27-08-09/sample.html
http://education.mysite.com/27-08-09/sample.html
我面临的问题是为两个模块分配了最后定义的路径。
任何人都可以为此提出解决方案。
答案 0 :(得分:15)
大家在浏览网页后,我想出了解决问题的解决方案
resources.router.routes.www.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.www.route = ":module.findchennai.com"
resources.router.routes.www.defaults.module = "www"
resources.router.routes.www.chains.index.type = "Zend_Controller_Router_Route"
resources.router.routes.www.chains.index.route = ":controller/:action/*"
resources.router.routes.www.chains.index.defaults.controller = "index"
resources.router.routes.www.chains.index.defaults.action = "index"
上面的代码将模块映射到子域
resources.router.routes.news.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.news.route = "news.findchennai.com"
resources.router.routes.news.defaults.module = "news"
resources.router.routes.edu.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.edu.route = "education.findchennai.com"
resources.router.routes.edu.defaults.module = "education"
resources.router.routes.edu.chains.list.type = "Zend_Controller_Router_Route"
resources.router.routes.edu.chains.list.route = ":categ/:page"
resources.router.routes.edu.chains.list.defaults.controller = "index"
resources.router.routes.edu.chains.list.defaults.action = "category"
resources.router.routes.edu.chains.list.defaults.page = 1
resources.router.routes.news.chains.list.type = "Zend_Controller_Router_Route"
resources.router.routes.news.chains.list.route = ":categ/:page"
resources.router.routes.news.chains.list.defaults.controller = "index"
resources.router.routes.news.chains.list.defaults.action = "category"
resources.router.routes.news.chains.list.defaults.page = 1
这解决了我遇到的问题,现在可以正确映射到以下网址
http://news.mysite.com/27-08-09/sample.html
http://education.mysite.com/27-08-09/sample.html
如果有人知道如何进一步优化上述代码,请告诉我。
答案 1 :(得分:0)
这两个子域是否都调用了相同的index.php?
如果他们不仅根据适当的子域设置路由,而不是在两个子域中设置两个路由。
如果他们从$ _SERVER ['HTTP_HOST']变量读取并根据子域设置正确的路由或在.htaccess文件中设置环境变量,那么您可以告诉您所在的子域。