views:

1616

answers:

3

Hi,

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.

A: 

Do both subdomains call into the same index.php?

If they don't only set the route based on the appropriate sub domain instead of setting both routes in both sub domains.

If they do either read from the $_SERVER['HTTP_HOST'] variable and set the correct route based on the subdomain or set an environment variable in your .htaccess file so you can tell which subdomain you are in.

smack0007
Hi,I have added a separate route which maps the sub domain and routes to it.resources.router.routes.www.type = "Zend_Controller_Router_Route_Hostname"resources.router.routes.www.route = ":module.mysite.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"
Nizam
Please add that as the answer.
smack0007
A: 

I have added the following route to map the subdomain with module

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"

along with the following .htaccess code

RewriteCond %{HTTP_HOST} !^(www|education|food|news|entertainment)\.mysite\.(com|local)
RewriteRule ^(.*)$ http://www.mysite.%2/$1 [R=302,QSA,L]

This works fine for the sub domains say

http://education.mysite.com/
http://news.mysite.com/

the page content of the sub domains are displayed in the following pattern

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

I have the following two routes to match the case and route it to the corresponding modules

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 problem I face is in the give current scenario when i call the page

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

the education module route which is defined last is mapped and I am not able to get the desired output as it checks for content in the education module.

Can anyone help me out of this problem

Nizam
+6  A: 

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.

Nizam
Thanks for the in-depth information. Exactly what I needed.
Brad F Jacobs