有人会向我解释这个功能吗?即函数beforeFilter的作用以及每行的作用。感谢。
function beforeFilter()
{
//Configure AuthComponent
$this->Auth->authorize = 'actions';
$this->Auth->actionPath = 'controllers/';
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'posts', 'action' => 'add');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
}
答案 0 :(得分:4)
记录代码
// `beforeFilter()` gets executed before the request forwarded to `action`
function beforeFilter() {
//Configure AuthComponent
// read http://book.cakephp.org/complete/1250/Authentication#authorize-1275
$this->Auth->authorize = 'actions';
// read http://book.cakephp.org/complete/1250/Authentication#actionPath-1279
$this->Auth->actionPath = 'controllers/';
// tells the Auth component the location of login action
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
// tells the Auth component where to redirect after successful login
$this->Auth->loginRedirect = array('controller' => 'posts', 'action' => 'add');
// tells the Auth component where to redirect after logout
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login'); }