Tuesday, January 31, 2012

Switch languages links

I have the following routes:
Router::connect("/:lang", array('controller' => 'pages', 'slug' =>
'home'), array('lang' => '[a-z]{3}', 'pass' => array('slug')));
Router::connect("/:lang/:controller", array(), array('lang' => '[a-
z]{3}', 'pass' => array('slug')));
Router::connect("/:lang/:controller/:slug", array(), array('lang'
=> '[a-z]{3}', 'pass' => array('slug')));

Router::connect('/', array('controller' => 'pages', 'slug' =>
'home'), array('pass' => array('slug')));
Router::connect("/:controller/:slug", array('action' => 'index'),
array('pass' => array('slug')));

And I need to generate the language switch links, I try this

$languages = array('French' => 'fre', 'English' => 'eng');

foreach($languages as $lang => $alias){
if($alias == Configure::read('Config.language')) continue;
echo $this->Html->link($lang, array_merge($this->passedArgs,
array('lang' => $alias)));
}

but I get links with the action inside them and the lang goes as named
parameter (ex. `/posts/index/post1/lang:eng`) and it should be `/eng/
posts/post1`

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: