2012-03-17 60 views
0

所以,我有一些問題。CI黑客路由

我只是想創建一些網站,訪問者可以與我的網站進行互動,如果他們註冊。 讓他們說他們已經提供了他們的用戶名,電子郵件,密碼,blah..blah..blah ... 然後,他們提供了他們的blah..blah..blah ..它會自動聯繫(如果他們的數據通過)到我的網站。 他們登錄我的網站後,他們必須再次提供更多數據,例如他們上傳了他們的個人資料照片,他們如何控制他們在我的網站的隱私,如一步一步註冊。

我不希望他們與我的網站互動,直到他們完成註冊。 如何使我網站中的每個頁面看起來都像註冊頁面,直到他們完成註冊。 這不像我會給這種功能正確。

if(is_login()){ 
    if(is_registration_complete()){ 
     //you're free to go 
    } else { 
     // complete your registration first 
    } 
} else { 
    //you're not logged in 
} 

在我的每一個控制器,如果你知道我的意思:)

如何globaly創建這個功能呢? 如果他們的註冊沒有完成,他們會去每個路線的註冊控制員。 如果他們完成註冊,他們會去,是的,你知道默認路線。

我很抱歉,如果我的英語不好,英語不是我的母語,對語法錯誤:)

回答

0

對不起,最簡單的可能是創建一個帶有你的檢查功能,然後把它列入在受影響的ControllerS的構造器中:

class Blog extends CI_Controller { 

     public function __construct() 
     { 
      parent::__construct(); 
      // Load the lib here or Autoload 
      $this->load->library('mylogincheckhelper'); 
      $this->mylogincheckhelper->is_complete(); 
     } 
} 

然後你在Lib中做所有的ckecks和路由。

+0

什麼是在is_complete()方法? 是否可以在該方法內加載視圖? 而不是從博客控制器再次加載另一個視圖? – 2012-03-17 07:40:03

0

您可以執行此操作的一種方法是通過extend the core CI_Controller創建自定義控制器。然後,您可以讓您的頁面控制器從您的自定義控制器擴展。通過擴展,您可以繼承父項的功能,並且可以運行父構造函數(或者在覆蓋它的情況下運行它),從而使它們對擴展它的任何人都「全局可用」。

//extend the core controller 
class MY_Controller extends CI_Controller { 

    //override to provide additional functionality 
    public function __construct(){ 

     //run the core controller 
     parent::__construct(); 

     //then do your login and registration checks here 
     //you can put code here, call another function or load a helper class 
     //or better, redirect them to your registration page 
    } 
} 

//your page's controller extending from your custom controller 
class Page extends MY_Controller { 

    //not overriding the constructor will execute the parent constructor 
    //every page that extends your extended controller will inherit it's functions 
    //and execute it's constructor 

} 
+0

我會試試這個,謝謝你的回答:) – 2012-03-17 07:47:23

0

用你的註冊後的東西創建一個視圖,並使它們有條件地可見。並將視圖包含在您的模板中。