Codeigniter Users Login Check
If you are using CI version bellow 2.0 then create new class in application/libraries/MY_Controller.php, otherwise in application/core/MY_Controller.php and all of your application controllers should extend from it. In this class in the __construct method you will check for the login status and send it to the views.
class MY_Controller extends CI_Controller{ public function __construct() { parent::__construct(); //Get the status which is array $login_status = $this->check_session(); //Send it to the views, it will be available everywhere //The "load" refers to the CI_Loader library and vars is the method from that library. //This means that $login_status which you previously set will be available in your views as $loginstatus since the array key below is called loginstatus. $this->load->vars(array('loginstatus' => $login_status)); } protected function check_session() { //Here goes your function }}
Also make sure your application controllers extend from this class
//application/controllers/index.phpclass Index extends MY_Controller{ public function __construct() { parent::__construct(); }}
In your views you can do this:<a href="<?php echo $loginstatus['url']; ?>"><?php echo $loginstatus['status']; ?></a>
This is possible cause the CI_Loader vars() method is doing extract to the parameters passed to it.