Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding sub domain based routes in Zend framework

I am newbie to Zend framework, I am using .ini file to add routes in my application.

I have 2 routes for different modules which

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"

the url pattern is like

http://news.mysite.com/27-08-09/sample.html

http://education.mysite.com/27-08-09/sample.html

the problem I face is the last defined route is assigned for both the modules.

can anyone suggest a solution for this.

like image 377
Nizam Avatar asked Aug 27 '09 11:08

Nizam


1 Answers

Hi after much browsing in the web I came up with this solution for my problem

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"

The above code maps the module with sub domain

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

This solves the problem I faced and now could map correctly to the following urls

http://news.mysite.com/27-08-09/sample.html
http://education.mysite.com/27-08-09/sample.html

Still if some one knows how to optimise the above code further, Please let me know.

like image 111
Nizam Avatar answered Oct 28 '22 14:10

Nizam