Reputation: 541
I have language-prefixed URLs working great (site.com/en/controller/action
and site.com/fr/controller/action
, etc.), but if somebody enters a URL without the language, I want to redirect to a URL that has the language. So site.com/controller/action
redirects to site.com/xx/controller/action
where xx
is a value specifying the language, that is stored in the session (or a cookie).
I suspect I can just look up the language
index in the $this->params
array, and simply redirect if I don't find it. Something like:
if (!isset($this->params['language']) {
$this->redirect(array('controller' => $this->controller, 'action' => $this->action, 'language' => $this->Session->read('Config.language')));
}
But my concern is that this would drop any POST or GET data.
What am I missing?
Thanks!
Upvotes: 0
Views: 489
Reputation: 740
I' not huge expert in this case but I have understood that it's good practise to always redirect POST data. So before checking language, do what you should do with POST data, and after that do a redirect with proper language in url.
Look this: Insert cakephp POST params into URL
You can also look this->params for GET data and pass that to $this->redirect to carry it on.
Upvotes: 1