I try to search on google for this question. I really want to load my MY_Login Library to all my controllers for check session. (not one by one) but except only login controller i don't want to load in.
Library
class MY_Login {
function __construct() {
parent::__construct();
// call with constructor.
$this->isLogin();
}
function isLogin() {
//source code
}
}
Any comments would be appreciated :)
You should use core MY_Controller on controllers like dashboard etc
application > core > MY_Controller.php
class MY_Controller extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library('login');
}
}
Controller
class Dashboard extends MY_Controller {
public function index() {
}
}
http://www.codeigniter.com/user_guide/general/creating_libraries.html Library example
class Login {
public function __construct() {
$this->CI =& get_instance();
$this->CI->load->library('session');
if ($this->CI->session->userdata('is_logged') == TRUE) {
} else {
$this->logout();
}
}
public function login
// How to use session in library example.
$this->CI->session->set_userdata(array('is_logged'=> true));
}
public function logout() {
$this->CI->session_unset_userdata('is_logged');
}
}
I would suggest reading more of the user guide first. http://www.codeigniter.com/user_guide/index.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.