2010年4月27日星期二

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

ok - that is much better than our solution!

Viktor

> -----Original Message-----
> From: Hector Virgen [mailto:djvirgen@gmail.com]
> Sent: Tuesday, April 27, 2010 7:14 PM
> To: dbenjamin
> Cc: fw-mvc@lists.zend.com
> Subject: Re: [fw-mvc] Language in URL: always a particular case !
>
> Have you tried specifying a regex requirement for the :lang parameter?
>
>
> resources.router.routes.default.type = "Zend_Controller_Router_Route"
> resources.router.routes.default.route = ":lang/:controller/:action/*"
> resources.router.routes.default.defaults.lang = "en-gb"
> resources.router.routes.default.defaults.module = "default"
> resources.router.routes.default.defaults.controller = "index"
> resources.router.routes.default.defaults.action = "index"
> resources.router.routes.default.reqs.lang = "[a-z]{2}-[a-z]{2}"
>
> Then, in your lang plugin, check the request early (like in
> routeShutdown) to see if the request matched a route. If not,
> you know the user didn't provide a valid language pattern,
> and you can forward or redirect to a valid page (maybe
> redirect to the same URL but prefixed with "en-gb/").
>
> --
> Hector
>
>
>
> On Tue, Apr 27, 2010 at 5:54 AM, dbenjamin
> <bd.webdev@gmail.com> wrote:
>
>
> Hi, The same subject again and again. Adding the locale
> into URL to simulate a "one folder per language" structure
> with MVC. Just like the official Zend website does, but how
> exactly ? :) It's really complicated to add this behaviour
> with Zend routes and by browsing forums i never found a
> viable solution. The solution that comes up most often is : -
> redefine default routes - a plugin to get lang param and
> initialize Zend_Locale/Zend_Translate But that's not enough !
> We need to handle the following cases : - the lang param is
> not valid - the lang param is missing (ex.
> http://www.my-website.com/contact has to be redirected to
> http://www.my-website.com/defaultlang/contact) Let's assume
> an user enter the following url :
> http://www.my-website.com/dsqdsq, we have to return a 404
> error page, handled by the ErrorHandler plugin. But that's
> not possible, in our plugin we will get "dsqdsq" as the lang
> param value and throwing manually a 404 error from within a
> plugin is not handled by the ErrorHandler. Plus, we will
> maybe have to redirect automatically the user to :
> "http://www.my-website.com/en-gb/dsqdsq", but "dsqdsq" is a
> module ? a controller ? an action ? Who knows and how to
> redirect to a good url. In other words, if the first param is
> not a valid lang, we have to add the default language to the
> url and shift all the parts of the url (complicated). I'm
> wasting a loooot of precious time with that stuff ! :) Is
> there a solution that works for all cases ? Maybe with apache
> rewrite rules ? Thanks. (and sorry if my english is sometimes
> hard :p) Cdt, Benjamin.
>
> ________________________________
>
> View this message in context: Language in URL: always a
> particular case !
> <http://zend-framework-community.634137.n4.nabble.com/Language
> -in-URL-always-a-particular-case-tp2067501p2067501.html>
> Sent from the Zend MVC mailing list archive
> <http://zend-framework-community.634137.n4.nabble.com/Zend-MVC
> -f663775.html> at Nabble.com.
>
>
>
>

没有评论: