Class instantiation in codeigniter |
How inbuilt classes like libraries,views are instantiated in codeigniter ?
eg:using new operator
With $this->load->library('lib_name');
And also understand that a call to
PHP Code: $this->load->library('lib_name'); // or load->model('lib_name'); The instance created is added to the controller and is accessed using PHP Code: $this->lib_name->some_method(); 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. |
Welcome Guest, Not a member yet? Register Sign In |