2011-02-02 47 views
0

有人會向我整體解釋這個功能嗎?即過濾器之前的功能以及每行的功能。謝謝。需要cakephp的Auth組件配置詳細信息?

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

它說,它做什麼的註釋。它配置AuthComponent。沒什麼神奇的。這是對屬性的簡單賦值。請澄清你的問題,指出你對此不瞭解的內容。 – Gordon 2011-02-02 16:50:41

+0

*(參考)* http://api.cakephp.org/class/auth-component – Gordon 2011-02-02 16:52:35

回答

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'); } 

你一定要讀這http://book.cakephp.org/complete/1250/Authentication