无法读取控制器CakePHP中的命名参数

无法读取控制器CakePHP中的命名参数,cakephp,cakephp-2.6,Cakephp,Cakephp 2.6,我正在尝试将命名参数传递给函数。它实际上是在$this->request->is'post'之前传递的,但是放置在此行之后的debugKit返回null。有什么好处 路线: http://localhost/bake/users/login/ref:post 控制器: public function login() { //it returns 'post' here successfully. debug($this->params['named']['ref']);

我正在尝试将命名参数传递给函数。它实际上是在$this->request->is'post'之前传递的,但是放置在此行之后的debugKit返回null。有什么好处

路线:

http://localhost/bake/users/login/ref:post
控制器:

public function login() {
    //it returns 'post' here successfully.
    debug($this->params['named']['ref']);
    if ($this->request->is('post')) {
        //it returns 'null' here.
        debug($this->params['named']['ref']);
    }
}

我使用了一种伪方法:

public function login() {
    //set the value to the view.
    $this->set('param', $this->params['named']['ref']);
    if ($this->request->is('post')) {
        $param = $this->request->data['param'];
    }
}
在视图中,我添加了一个隐藏字段:

<input type="hidden" name="data[param]" value="post"/>
因此,当表单提交时,它将获得值。

如果您懒惰:

$this->request->query('ref')
如果你好奇:

文件


源代码

可能是因为您正在发布到不同的url,而url中没有该url。请用您正在使用的CakePHP版本标记问题,并放置例如debug$\u POST的输出;问题中的debug$\u SERVER['REQUEST\u URI']仅返回/bake/users/login。但是在所有其他控制器和函数中都没有这样的问题。返回/bake/users/login没有歧义-这是调试时的url。我建议您在答案后面添加更多细节和/或推理,纯代码回答可能会修复它正在回答的明确问题,但有关原因等的详细信息可能会允许某人从谷歌或其他搜索引擎获取此信息,以解决他们自己的类似问题。完成,尽管我给出了确切的答案,但我给出了查看内容/位置,打开API文档并寻找我建议的方法应该需要很长时间。