I am very new in CakePHP and I am trying to append the language to the URL in case the user type: mydomain(dot)com/users
Then the Url has to change to http://mydomain.com/eng/users
Well, I am using Translate behavior and in my routes.php file I have :
Router::connect('/:lang/:controller/*', array(), array('lang' => '[a-z]{3}'));
Router::connect('/:lang/:controller/:action/*', array(), array('lang' => '[a-z]{3}'));
Ok so far everything works perfectly. But when in my contorllers/AppController.php I try to append the url I get an error
This is what I have in my afterFilter function:
if (empty($this->params['lang']) ){
//Redirect to a language url
$this->redirect(array(
'lang'=> 'eng',
'controller' => $this->params['controller'],
'action' => $this->params['action'])
);
}
This works but when I try to go to the http:/mydomain.com/users/View/4 in the url I can see http:/mydomain(dot)com/eng/users/View/4 but what I see in the browaer is http:/mydomain(dot)com/users/View/
My question for you would be : What is the best way to achieve what I need ? There is a plugin for doing this? or how can I handle this in CakePHP?