0

我正在尝试将命名参数传递给函数。它实际上是在之前通过的$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']);
    }
}
4

2 回答 2

0

如果你很懒:

$this->request->query('ref')

如果你好奇:

文档在这里

源代码在这里

于 2015-09-21T13:16:01.617 回答
0

我使用了一种伪方法来解决它:

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"/>

所以它通过提交表单获取值。

于 2015-09-17T16:52:04.307 回答