Welcome Guest, Not a member yet? Register   Sign In
Class instantiation in codeigniter
#4

And also understand that a call to
PHP Code:
$this->load->library('lib_name'); // or load->model('lib_name'); 
instantiates the class using new.

The instance created is added to the controller and is accessed using
PHP Code:
$this->lib_name->some_method();
//or
$this->lib_name->some_property
anywhere the controller is in scope.

In a case where the controller is not in scope a reference to can be obtained using get_instance() eg.
PHP Code:
$CIĀ =& get_instance(); 

The Utilizing CodeIgniter Resources within Your Library section of the documentation explains this very well.

It may be useful to know that classes instantiated using the loader ($this->load->...) are singletons.
Reply


Messages In This Thread
Class instantiation in codeigniter - by Santi - 03-13-2018, 03:42 AM
RE: Class instantiation in codeigniter - by dave friend - 03-16-2018, 07:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB