2012-04-06 155 views
0

我在我的帖子控制器下面的方法:将参数传递给方法的CakePHP

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

如果我请访问以下网址:/posts/index/filter:test它会返回null,但如果我使用/posts/index/test它将返回测试...

我的印象是Cake处理过的参数是默认命名的?

我尝试使用类似的路线固定的:

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

但它仍然回来为空!就好像过滤器没有通过该方法...

我该如何解决这个问题?

回答

1

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

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

但是,它甚至命名参数? – Cameron 2012-04-06 21:44:18

+0

当你把它传递给像这样的url:/ index/filter:value - 它被命名。 – Headshota 2012-04-06 21:46:12

+0

那么,为什么我的方法不适合呢? – Cameron 2012-04-06 21:47:04