1

所以这是我的问题。我有一个网站,我们目前正在使用 cakephp 翻译成法语。当我在带有诸如“www.mydomain.com/eng/store/view/1”之类的网址的页面上时,我在法语链接中看到的网址是“www.mydomain.com/fre/store/view/” .

这是我的 routes.php 中与商店页面相关的代码

Router::connect('/:language/:controller/:action/*',
                   array(),
                   array('language' => '[a-z]{3}'));
Router::connect('/store/:action/*', array('controller'=>'products'));
Router::connect('/store', array('controller'=>'products', 'action'=>'index'));

在我的 app_helper.php 我有

function url($url = null, $full = false) {
        if(!isset($url['language']) && isset($this->params['language'])) {
          $url['language'] = $this->params['language'];
        }     

        return parent::url($url, $full);
    }

所以我的问题是:我应该怎么做才能让我的链接在切换语言时保留产品的最后一个参数?

注意:该链接非常适用于在 url 中只有一个控制器和一个操作的页面。

4

2 回答 2

1

I have found the actual problem why my parameters were not following in the language link. I'm not entirely sure this is the best option, but it works for me.

When adding the links for the language instead of having :

echo $this->Html->link('English', array('language'=>'eng'))

I am using

echo $this->Html->link('English', array('language'=>'eng')+$this->params['pass']);

Looking to see if there was a routing issue was not entirely useless as I have found many flaw that made other pages that would not go to the correct url, mainly the pages under the pages folder. Adding

Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
Router::connect('/:language/pages/*', array('controller' => 'pages', 'action' => 'display'), array('language' => '[a-z]{3}'));

Did the trick for these.

于 2013-12-11T20:17:06.567 回答
0

这适用于所有情况并传递变量:

Router::connect('/action/**', array('controller' => 'controller_name', 'action'=>'action_name'));

在这里,如果您想限制您的 url 并将变量添加到您的 url =>eg controller/action/variable

 Router::connect('/action/:id', array('controller' => 'controller_name', 'action'=>'action_name')
                              , array('pass'=>array('id')));

这里是参考

希望能帮助到你

于 2013-10-30T09:29:33.677 回答