将参数传递给 CakePHP 中的方法


Passing parameters to methods in CakePHP

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

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

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

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

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

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

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

我该如何解决这个问题?

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

$this->params['named']['filter']