hi i am using codeigniter , in my controller constructor sometimes i use $this sometimes $this->ci
in two constructors i have use like this
public function __construct()
{
$this->ci =& get_instance();
$this->ci->load->library('form_validation');
$this->ci->load->library('catalog/CatalogManager');
}
function __construct()
{
parent::__construct ();
$this->ci = & get_instance ();
$this->load->library ( 'auth_lib' );
$this->load->library ( 'session' );
}
when passing data to view i use
$this->ci->data and $this->data in above two cases .
neither gives errors , but i am confused , what is the correct use.
please help………..
All controllers extend the main CI_Controller, so calling something like
$this->loadmeans accessing the parent methodload()inside the parent class CI_Controller.$this->ciworks because with$this->ci = &get_instance()you’re calling a reference to the main controller class…again. If you look in the bootstrap file (IIRC. Or the codeigniter.php file) there’s the functionget_instance(), which does nothing but return (by reference) the instance of the CI_Controller class.So, basically, calling
$this->ci->loadand$this->loadare the same exact thing, only that the first is unnecessary within a Controller/Model/View because the system is already doing that in the parent class (through the method load).If you have a look at libraries, for ex., you’ll see instead that using
$this->ci->method()is necessary, because you need to have available all the methods of the CI_Controller, which is a kind of “super class” that drives the whole framework.Have a look at the loader class and the CodeIgniter class to grasp how CI internally works.