(07-29-2015, 09:51 PM)freddy Wrote: How about load session when users login cause i feel wasting time to write session every single controller !
Create a base controller (e.g. MY_Controller) which loads the session library. If you need it to be loaded only under certain conditions, you can add a property which controls whether the library is loaded, then set it accordingly. For example, you could create a protected property called $loadSession and default it to TRUE, then a controller which shouldn't load the session can override the property and set it to FALSE.
PHP Code:
class MY_Controller extends CI_Controller
{
protected $loadSession = TRUE;
public function __construct()
{
parent::__construct();
if ($this->loadSession) {
$this->load->library('session');
}
}
}
PHP Code:
class Cli_controller extends MY_Controller
{
protected $loadSession = FALSE;
public function __construct()
{
parent::__construct();
}
}