0

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?

4

1 回答 1

0

那么问题出在我的router.php中

我有 ---> Router::connect('/:lang/:controller/ ', array(), array('lang' => '[az]{3}')); Router::connect('/:lang/:controller/:action/ ', array(), array('lang' => '[az]{3}'));

而正确的做法是 -----> Router::connect('/:lang/:controller/:action/ ', array(), array('lang' => '[az]{3}')) ; Router::connect('/:lang/:controller/ ', array(), array('lang' => '[az]{3}'));

于 2013-10-02T03:55:50.027 回答