2011-01-20 52 views
0

我試圖讓我的管理路由與驗證組件一起工作。我想要以下路由工作。驗證組件問題

Router::connect('/admin', array('controller' => 'pages', 'action' => 'index', 'admin' => true)); 

但是當我輸入/ admin時,它重定向到/ admin/users/login並顯示此錯誤。

Create UsersController::admin_login() in file: cms.local/controllers/users_controller.php 

這是我的app_controller代碼。

class AppController extends Controller { 

    var $components = array('DebugKit.Toolbar','Auth','Session'); 

    function beforeFilter(){ 

     //Set up Auth Component 
     $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login'); 
     $this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'admin_index'); 
     $this->Auth->allow('display'); 

    } 

} 

users_controller

<?php 
class UsersController extends AppController { 

    var $name = 'Users'; 

    function login(){ 

    } 

    function admin_logout(){ 
     $this->Session->destroy(); 
     $this->redirect($this->Auth->logout()); 
    } 

} 
?> 

如果您需要更多的信息,讓我知道。

感謝

回答

0

別擔心,所有的工作確定:)

在AppController中:: beforeFilter()你說,爲了登錄,根據loginAction是用戶/登錄(用戶/ admin_login如果管理員= >真)

當你去與管理=>真實頁/指數,您還沒有登錄,您將被重定向到用戶/ admin_login,並作爲這告訴:

但是當我鍵入在/管理它重新指向/ admin/users/login並顯示此錯誤。

Create UsersController::admin_login() in file: cms.local/controllers/users_controller.php

的方法UsersController :: admin_login()找不到,你應該創建它。

+0

爲什麼需要兩個登錄的功能呢?登錄和admin_login。我添加了admin_login,但後來它要求查看它。 auth組件不像管理路由嗎? – madphp 2011-01-20 18:39:49

0

您可以通過在loginAction中指定'admin' => false來強制Auth使用非前綴登錄操作。這樣,所有需要進行身份驗證的操作都將使用非前綴登錄操作。因此,您的beforeFilter會是這個樣子:

function beforeFilter(){ 

    //Set up Auth Component 
    $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login', 'admin' => false); 
    $this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'admin_index'); 
    $this->Auth->allow('display'); 

} 

同樣,你可以走另一條路,並指定「管理員」 =>真的只用admin_login

0

這個工作對我罰款: -

function beforeFilter() { 
    if (isset($this - > params['admin'])) { 
     $loggedAdminId = $this - > Session - > read("adminid"); 
     if (!$loggedAdminId && $this - > params['action'] != "admin_login") { 
      $this - > redirect("/admin/admins/login"); 
      $this - > Session - > setFlash('The URL you followed requires you login.'); 
     } else { 
      $this - > Auth - > allow('*'); 
     } 
    } else { 
     $this - > Auth - > loginAction = array('controller' = > 'users', 'action' = > 'login', 'admin' = > false); 
     $this - > Auth - > loginRedirect = array('controller' = > 'users', 'action' = > 'admin_index'); 
    } 
}