2011-02-02 13 views
0

誰かがこの機能を私に説明してくれるでしょうか?すなわち、beforeFilterの機能とそれぞれの行が何をしているのかということです。ありがとう。cakephpの認証コンポーネント設定の詳細が必要ですか?

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

+0

*(参考)* http://api.cakephp.org/class/auth-component – Gordon

+3

これは非常に悪い質問のタイトルです。 – Shikiryu

答えて

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

+0

ログインとログアウトのようなものは、ユーザのコントローラのログインとログアウト機能の中にいないのはなぜですか? – Cameron

+0

彼らは実際には**リダイレクトしません。成功後にリダイレクトする場所を教えてくれるだけです。これは通常は 'app_controller.php'で行われ、すべてのアクションで設定が同じになります。あなたはあなたの行動のどこにでもそれらを上書きすることができます(*通常はあなたは*する必要はありません)。 – Ish

関連する問題