【问题标题】:Trouble with Router::url() when using named parameters使用命名参数时 Router::url() 出现问题
【发布时间】:2010-05-11 22:14:18
【问题描述】:

我正在使用 CakePHP 的 HtmlHelper 通过以下方式生成简单的链接:

$html->link("Newest", array(
            'controller' => 'posts',
            'action' => 'listView',
            'page'=> 1,
            'sort'=>'Question.created',
            'direction'=>'desc',
    ));

具有以下路由规则:

Router::connect('/foobar/*',array(
        'controller' => 'posts',
        'action' => 'listView'
));

链接很好地生成为/foobar/page:1/sort:Question.created/direction:desc。正如我所愿,它使用我的 URL 前缀而不是控制器/动作名称。

但是,对于某些链接,我必须添加这样的命名参数:

$html->link("Newest", array(
            'controller' => 'posts',
            'action' => 'listView',
            'page'=> 1,
            'sort'=>'Question.created',
            'direction'=>'desc',
            'namedParameter' => 'namedParameterValue'
    ));

本例中的链接指向/posts/listView/page:1/sort:Question.created/direction:desc/namedParameter:namedParameterValue。但是我不想在我的 URL-s 中有控制器/动作名称,为什么在这种情况下 Cake 会忽略我的路由器配置?

【问题讨论】:

    标签: php cakephp


    【解决方案1】:

    相当无证,但mentioned,这解决了它:

    Router::connectNamed(array('namedParameter', 'page', 'sort', 'direction'));
    

    【讨论】:

      猜你喜欢
      • 2018-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-07
      • 2010-11-24
      • 2020-11-28
      • 1970-01-01
      相关资源
      最近更新 更多