2009-07-28 59 views
1

我有我的前端控制器,其他控制器的功能,我使用DX驗證庫。CI借在另一個控制器

我想用DX驗證的註冊,但它包含在我的頭版控制器......我可以簡單地複製粘貼的功能,但有一個更好的方式來做到這一點?

回答

1

你嘗試登錄並在頭版控制器註冊用戶?你需要根據installation instructions安裝DX驗證和諮詢一些手冊中的實例和功能的引用。

你需要加載DX驗證庫在構造函數:

class Auth extends Controller 
{ 
    function Auth() 
    { 
     parent::Controller(); 
     // Load library 
     $this->load->library('DX_Auth'); 
     $this->load->library('Form_validation'); 
    } 

    // implement other login functions like the examples 
    // using the library: 

    function login() 
    { 
     if (!$this->dx_auth->is_logged_in()) { 
      $is_valid = $this->form_validation->run('login'); 
      $username = $this->input->post('username'); 
      $password = $this->input->post('password'); 

      if ($is_valid && $this->dx_auth->login($username, $password)) { 
       // redirect somewhere 
      } else { 
       // show some errors 
      } 
     } 
    } 

    // other authentication functions 
} 

如果你想你可以做一個幫手來保存您的身份驗證功能,因此你可以從任何控制器訪問它們。按照安裝說明,讓您的數據庫建立和某種基本的用戶註冊和登錄工作的 - 他們是相當全面。

+0

我是一個noob,所以MVC的東西剛剛開始下沉... 這是有道理的。謝謝! – 2009-07-28 19:34:11