嗨傢伙,我需要在這行代碼幫助包含在簡單的身份驗證和授權應用部分CakePHP的教程:
if (in_array($this->action, array('edit', 'delete'))){
}
我知道the in_array()
功能做,但我不知道$this->action
是什麼都關於它包含什麼,$this->action
首先做什麼?
任何人都可以請幫我進入這個?
嗨傢伙,我需要在這行代碼幫助包含在簡單的身份驗證和授權應用部分CakePHP的教程:
if (in_array($this->action, array('edit', 'delete'))){
}
我知道the in_array()
功能做,但我不知道$this->action
是什麼都關於它包含什麼,$this->action
首先做什麼?
任何人都可以請幫我進入這個?
$這個 - >行動返回當前的例如行動 名稱: 您的請求= /職位/編輯 控制器:
class PostsController extends AppController{
// ...
public function beforeFilter(){
parent::beforeFilter();
debug($this->action); // = edit
}
// ...
}
它應該$ this-> params ['action']而不是$ this-> action。
$this->action returns the action name of controller
你的情況
,in_array($這個 - >行動,數組(「編輯」,「刪除」)檢查操作名稱編輯或刪除。
for debugging you can use
pr($this->action);
你可以使用parent::beforeFilter();
聲明用戶驗證。
對於在控制器
,你必須使用
function beforefilter()
{
parent::beforeFilter();
}
此功能將檢查用戶權限
或更好的嘗試
debug($this)
這會讓你知道其他類變量也是如此。
它包含您所在操作的名稱。 –