use ion auth authentication for codeigniter in another controller

后端 未结 3 2035
长发绾君心
长发绾君心 2021-01-22 09:03

I am trying to build a web application with codeigniter. I have installed Ion Auth as my authentication model.

The default Auth.php controller authenticates the user and

3条回答
  •  既然无缘
    2021-01-22 09:47

    First autoload the ion_auth library. If u simply want to check if the user is logged-in, just check it in every controller's constructor u load

    public function __construct() {  
        parent::__construct();
    
        if (!$this->ion_auth->logged_in()) {
           // redirect to login view
        } 
    }
    

    If u happen to have multiple groups , u can create a new controller inside application/core/MY_controller.This controller will check whether user is logged in.You can extend this base controller to create new controller.A very good explanation on this is given by David john.Check this link .

提交回复
热议问题