views:

227

answers:

1

Hello,

I am playing with Zend 1.9 and would like to have the language parameter as subdomain.

Like : http://en.site.com

Is it possible to get the language in .htaccess and set it to an environment variable which I can use in Zend ?

What is the best way to achieve what I want ?

-- added --:

I added this into my routes.ini :

[routes]

routes.lif.type = "Zend_Controller_Router_Route_Hostname"
routes.lif.route = ":language.domain.:tld"
routes.lif.reqs.language= "[a-z]{2}"
routes.lif.defaults.controller = "index"
routes.lif.defaults.action = "index"
routes.lif.defaults.language = "en"

; default
routes.lif.chains.default.type = "Zend_Controller_Router_Route"
routes.lif.chains.default.route = "/:controller/:action"
routes.lif.chains.default.defaults.controller = index
routes.lif.chains.default.defaults.action = index

; register
routes.lif.chains.register.type = "Zend_Controller_Router_Route"
routes.lif.chains.register.route = "/register"
routes.lif.chains.register.defaults.controller = "register"
routes.lif.chains.register.defaults.action = "newuser"

; details
routes.lif.chains.band.type = "Zend_Controller_Router_Route"
routes.lif.chains.band.route = "/details/:name"
routes.lif.chains.band.defaults.controller = "details"
routes.lif.chains.band.defaults.action = "getdetails"

This is working well if I go to : http://en.domain.com/details/joe But unfortunatly if I remove subdomain : http://domain.com/details/joe the default action is not called and I get

Message: Action "joe" does not exist and was not trapped in __call()

Do you have an idea ?

Thanks guys.

Thierry

+1  A: 

You're in luck - there's a Zend_Controller_Router_Route_Hostname which can be used instead for exactly this purpose. If you want to achieve custom routing in the part after your domain, you'll need to take a look at Zend_Controller_Router_Route_Chain.

David Caunt
thanks a lot. I added my routes.ini but I get a problem, please see my edit. Thanks again
thierryb
In this case, the hostname route does not match, so the following route is not used. You will have to define another (normal) route which does the same thing, but doesn't have the hostname route chained before.
David Caunt