我的帖子控制器中有以下方法:
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']