2013-04-29 108 views
0

我無法遵循cakephp blog authorization教程。顯示下面的代碼,但由於它沒有很好的評論,我不確定這些參數究竟是什麼。cakephp授權數組參數

我有一個iteminfo動作的項目控制器,我只想讓特定項目的創建者能夠查看。它是通過以下網址,其中數字是itemnumber訪問和iteminfo是動作

/items/iteminfo/3 

例如

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

    // The owner of a post can edit and delete it 
    if (in_array($this->action, array('edit', 'delete'))) { 
     $postId = $this->request->params['pass'][0]; 
     if ($this->Post->isOwnedBy($postId, $user['id'])) { 
      return true; 
     } 
    } 

    return parent::isAuthorized($user); 
} 

我試圖修改它只是這個

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

    // The owner of a post can edit and delete it 
    if (in_array($this->action, array('iteminfo'))) { 
     print_r($this->request->params); //attempting to view the params array 
    } 

    return parent::isAuthorized($user); 
} 

我只是想查看params數組,所以我知道在我的iteminfo操作中要修改什麼。有什麼辦法可以查看嗎?基本上我想看看數組的組成部分是什麼,所以我知道要引用什麼。

這裏是項目表。

itemid userid itemname itemcost datecreated 

回答

0

你可以嘗試這樣做:

if (in_array($this->action, array('iteminfo'))) { 
    debug($this->request->params); 
    exit; 
} 
+0

嗯,我猜混亂的一部分還在於isAuthorized是如何被調用。它是CakePHP的一部分,如果聲明瞭該函數,它將一直被檢查,還是必須從我的iteminfo控制器調用它? – user2268281 2013-04-29 03:29:23

+0

@ user2268281 yes isAuthorized是AppController的一部分,它是Cake的Auth組件的一部分,您可以在cakephp doc的auth組件中查看詳細信息.. – 2013-04-29 04:13:12