2009-07-28 58 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