【问题标题】:cake php Can someone explain $this->request->params['pass'][0];?cake php 有人可以解释一下 $this->request->params['pass'][0]; 吗?
【发布时间】:2013-12-03 19:04:29
【问题描述】:

http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html

我正在关注 cakephp 网站上的本教程。我被困在了这个

public function isAuthorized($user) {
        // All registered users can add posts
        if ($this->action === 'add') {
            return true;
        }

        if (in_array($this->action, array('edit', 'delete'))) {
            $postId = $this->request->params['pass'][0]; //what is this?

            if ($this->Post->isOwnedBy($postId, $user['id'])) {
                return true;
            }
        }
        return parent::isAuthorized($user);
    }

这是什么意思?我知道 $this 指的是控制器,但 param['pass'] 是什么?他们在哪里以及如何得到这个?

$postId = $this->request->params['pass'][0];

【问题讨论】:

    标签: php cakephp


    【解决方案1】:

    这些是在请求字符串或发布变量中传递的参数。

    http://book.cakephp.org/2.0/en/controllers/request-response.html

    CakeRequest 公开了几个访问请求的接口 参数。第一个是作为对象属性,第二个是数组 索引,第三个是通过 $this->request->params:

    【讨论】:

    • 有什么方法可以记录 $this->request->params['pass'][0];是通过吗?使用 cakephp 调试工具包?
    • @artSir 是的,你应该在调试工具栏中看到它。
    【解决方案2】:

    不确定这是否是最佳答案,但我所要做的就是返回 false

    if ($this->Post->isOwnedBy($postId, $user['id'])) {
                    return true;
                }else {
                    return false;
                }
    

    【讨论】:

    • 好吧,它可能已经解决了您遇到的问题,但这绝对不是您自己问题的答案,您要求对变量进行解释,而先前的答案提供了这一点,您应该接受那个.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-22
    • 2016-12-12
    • 2011-03-02
    • 1970-01-01
    相关资源
    最近更新 更多