2013-03-18 50 views
0

我的主控制器檢查wheter的用戶是管理員與否,然後重定向到一個用戶/註冊這是一個子類主控制器誰再次檢查,如果用戶是管理員或不 ...所以那麼重定向是在循環,我不知道在哪裏更好地把登錄功能?主控制器檢查登錄和循環重定向(笨)

Admin_Controller -> { 

    child1_Controller -> { 

    function login() 
    { 
     //render login page, but can't because the main class constructor is checking login and redirecting again here 

    } 

    } 

} 

回答

0

看看運行的pre_controller鉤來檢查用戶的詳細信息,而不是使用構造

http://ellislab.com/codeigniter/user-guide/general/hooks.html

+0

但掛鉤是全球性的,我想使用它,只有當管理員控制器執行 – Hello 2013-03-18 09:24:40

+0

有兩種方法可以處理這個問題,無論是在你的鉤子上做一個簡單的URI檢查。如果($這個 - > URI->段(1)===「管理員」),或者你必須拉登錄表單動作出來的控制器是做檢查 – philipobenito 2013-03-18 09:26:49