簡體   English   中英

cake php有人可以解釋$ this-> request-> params ['pass'] [0];?

[英]cake php Can someone explain $this->request->params['pass'][0];?

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];

這些是在Request String或Post Variables中傳遞的參數。

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

CakeRequest公開了幾個用於訪問請求參數的接口。 第一個是作為對象屬性,第二個是數組索引,第三個是通過$ this-> request-> params:

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM