0

我的帖子控制器中有以下方法:

public function index( $filter = null )
{
    debug($filter); exit;
}

如果我访问以下 URL:/posts/index/filter:test它将返回 null 但如果我使用/posts/index/test它将返回 test...

我的印象是 Cake 默认将传递的参数视为命名?

我尝试使用以下路线解决此问题:

Router::connect('/test', array('controller'=>'posts','action'=>'index','filter'=>'test'));

但它仍然返回为空!好像过滤器没有传递给方法......

我该如何解决?

4

1 回答 1

1

如果需要获取命名参数,可以使用控制器的 params 属性:

$this->params['named']['filter']
于 2012-04-06T21:37:43.500 回答