0

我想要实现的是我只能更改 url 中的语言前缀,但是遇到问题......有我的路线:

$lang_regexp = implode('|', Configure::read('Config.languages'));
Router::connect('/', array('controller' => 'languages', 'action' => 'choose'));
Router::connect('/:lang/:controller/:action/*',
               array(),
               array('lang' => $lang_regexp));


// actual default page; can be any controller
    Router::connect('/:lang/pages/ajax_newsletter', array('controller' => 'pages', 'action' => 'ajax_newsletter'));
    Router::connect('/:lang/',
    array('controller' => 'pages', 'action' => 'index',  'home'),
    array('lang' => $lang_regexp));
    Router::connect('/:lang/:slug', array('controller' => 'pages', 'action' => 'pages'), array('lang' => $lang_regexp));
    Router::connect('/:slug', array('controller' => 'pages', 'action' => 'pages'), array('lang' => $lang_regexp));

    Router::connect('/:lang/special_offers', array('controller' => 'pages', 'action' => 'offers'));
    Router::connect('/:lang/special_offers/*', array('controller' => 'pages', 'action' => 'offers_city'));
    Router::connect('/:lang/news/*', array('controller' => 'pages', 'action' => 'news_article'));
    Router::connect('/:lang/news', array('controller' => 'pages', 'action' => 'news'));
    Router::connect('/:lang/:slug/:id/*', array('controller' => 'pages', 'action' => 'offers'), array('lang' => $lang_regexp));

    Router::connect('/cities/select', array('controller' => 'cities', 'action' => 'select'));
    Router::connect('/cities/select/*', array('controller' => 'cities', 'action' => 'select'));

我的语言切换器:

$this->html->link($this->html->image('flag_ru.gif',  array("alt"=>"", "width"=>"14px", "height"=>"12px", "title"=>"")), array("lang" => "rus"), array('escape' => false));

:lang/:slug是菜单条目,所以如果我localhost/eng/contact在语言更改后有菜单,我会得到localhost/rus/pages/pages......如何只更改语言前缀?

4

2 回答 2

0

您可以访问$this->request->controllerand $this->request->action,以及passandnamed用于传递和命名的参数。

$this->html->link($this->html->image('flag_ru.gif',  array("alt"=>"", "width"=>"14px", "height"=>"12px", "title"=>"")), array("lang" => "rus", "controller" => $this->request->controller, "action" => $this->request->action), array('escape' => false));

例如,应该工作。

有关详细信息,请参见此处

于 2012-09-04T00:02:49.197 回答
0

本文: http: //nuts-and-bolts-of-cakephp.com/2008/11/28/cakephp-url-based-language-switching-for-i18n-and-l10n-internationalization-and-localization/交易正是在这种创建一种语言路径以及自动将语言添加到所有链接的情况下。

于 2012-12-13T20:41:22.713 回答