0

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!

Siguza
  • 21,155
  • 6
  • 52
  • 89
Eli
  • 14,779
  • 5
  • 59
  • 77

2 Answers2

0

You could make a plugin that use the preDispatch event to look if the language has been chosen (e.g stored in cookie or session) and redirect to the landing page if not.

Look here zend framework plug-in - predispatch() and the ZF's action plugin documentation.

That's what I do to force login in my app.

Now in your position what I would really do would be detecting the language of the user with a fallback to English and a switch widget somewhere in your navbar.

Community
  • 1
  • 1
conradfr
  • 184
  • 2
  • 8
0

Don't ever use bootstrap file (and I'm talking about both Bootstrap.php and index.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 lang variable 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 just http://example.com/xx/...), it automatically uses this part so set the lang param. 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.

raina77ow
  • 103,633
  • 15
  • 192
  • 229