Welcome Guest, Not a member yet? Register   Sign In
Things to Configure Before Coding?
#20

(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();
    }

Reply


Messages In This Thread
RE: Things to Configure Before Coding? - by Narf - 07-30-2015, 01:36 AM
RE: Things to Configure Before Coding? - by mwhitney - 07-31-2015, 09:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB