2010年4月28日星期三

Re: [fw-mvc] RE: Language in URL: always a particular case !

You should be able to satisfy all of those conditions with a single route. You can make trailing parameters optional by providing a default value.

The only problem is I don't know how to make the "module" parameter optional while still accepting controller/action parameters. For example, you probably want this to go to your admin module:

/en-us/admin/foo/bar

while this goes to your default module

/en-us/foo/bar

Unless I'm mistaken, the basic route can't handle this, so you may need to always provide the module in the URL:

/en-us/default/foo/bar

Also, the reason why your routes are not working is because they work in LIFO order (so from the bottom up). Once a route matches the request (that is, the url is in the expected format), then that route is used. The problem is you have two routes with the same parameter signature ":module/:controller" and ":controller/:action". The router does not know the difference between your named parameters, so as soon as the format looks right it will use that route.

--
Hector


On Wed, Apr 28, 2010 at 8:44 AM, dbenjamin <bd.webdev@gmail.com> wrote:

Hello,

Thanks for your help, it's almost ok but there is still a problem.
I don't know exactly the order to define routes.

For example, i've created a very simple app with two modules, front and
admin. Front module has a IndexController with an index action and Admin
module has a ContactController with an index action.

According to the ZF documentation i should have  :
[code]
resources.router.routes.m.route = "/:locale/:module"
resources.router.routes.m.defaults.module = front
resources.router.routes.m.defaults.controller = index
resources.router.routes.m.defaults.action = index
resources.router.routes.m.reqs.locale = "^([a-z]{2}-[a-z]{2})$"
resources.router.routes.m.defaults.locale =

resources.router.routes.mc.route = "/:locale/:module/:controller"
resources.router.routes.mc.defaults.module = front
resources.router.routes.mc.defaults.controller = index
resources.router.routes.mc.defaults.action = index
resources.router.routes.mc.reqs.locale = "^([a-z]{2}-[a-z]{2})$"
resources.router.routes.mc.defaults.locale =

resources.router.routes.ca.route = "/:locale/:controller/:action"
resources.router.routes.ca.defaults.module = front
resources.router.routes.ca.defaults.controller = index
resources.router.routes.ca.defaults.action = index
resources.router.routes.ca.reqs.locale = "^([a-z]{2}-[a-z]{2})$"
resources.router.routes.ca.defaults.locale =

resources.router.routes.default.route =
"/:locale/:module/:controller/:action"
resources.router.routes.default.defaults.module = front
resources.router.routes.default.defaults.controller = index
resources.router.routes.default.defaults.action = index
resources.router.routes.default.reqs.locale = "^([a-z]{2}-[a-z]{2})$"
resources.router.routes.default.defaults.locale =
[/code]

But with the url : http://local.cosplay-it-teasing.com/en-us/dsqdqs
I don't get a Invalid controller exception and
http://local.cosplay-it-teasing.com/en-us/index or
http://local.cosplay-it-teasing.com/en-us/index/index don't work either.

If i change order of routes i can obtain it, but :
http://local.cosplay-it-teasing.com/en-us/admin/contact
Throws an Invalid Controller exception when the module/controller exist.

Any idea ?

Except that i think that's a better way to redirect earlier from bootstrap
or application plugin resource rather than from a controller plugin.


Thanks.

Cdt,
Benjamin.
--
View this message in context: http://zend-framework-community.634137.n4.nabble.com/Language-in-URL-always-a-particular-case-tp2067501p2072857.html
Sent from the Zend MVC mailing list archive at Nabble.com.


没有评论: