I’m just new to Zend Framework. Currently what I’m trying to do is when user access my website
they will first see a select box with two language such as english and germany to choose.
Only when they make a selection, the browser will redirect them to the index controller of that specific language page.
So my question is how to make a select box in bootstrap file or any kind of possible ways to do that and how to redirect user after that? Any solution will be much appreciated!
Don’t ever use bootstrap file (and I’m talking about both
Bootstrap.phpandindex.php) for this kind of operations. First, it just won’t work the way you ask; second, you’ll mess your app’s structure big time.Instead you may use one of the following approaches:
1) add some predispatch hook that will check whether the choice has already been made by checking the user’s cookies. If it is, proceed with request as usual (probably setting some Zend_Registry
langvariable to be used later), if not, redirect for the language choosing page; the latter should store the choice made in cookies.2) implement a simple rule in your Router/mod_rewrite: when the requested URL contains ‘the language part’ (
http://example.com/lang/xx/...or justhttp://example.com/xx/...), it automatically uses this part so set thelangparam. If not, the request is automatically redirected to the language choosing page. The latter, in turn, leads the user to a language-specific page, where all the links are made language-specific.The latter approach is inferior, in my opinion, as user will have to use a language-tuned gateway all the time. But you don’t have to store this info in cookies.