Php $ CI & amp; get_instance ();, phpci. Php $ CIget_instance (); for php beginners of phpci, someone writes this, $ CIget_instance (); to access the original CodeIgniter resources in your custom class library, you must use get_instance () function php $ CI = & get_instance ();, phpci
Someone writes this in php for beginners, $ CI = & get_instance ();
To access the original CodeIgniter resources in your custom class library, you must use the get_instance () function. This function returns a CodeIgniter super object.
In general, you can use $ this to call any available CodeIgniter functions in your controller functions:
$ This-> load-> helper ('URL ');
$ This-> load-> library ('session ');
$ This-> config-> item ('base _ url ');
Etc.
$ This only applies to your own controllers, models, and views. when you want to use the original CodeIgniter class in a custom class, you can do this:
First, define the CodeIgniter object to assign a variable:
$ CI = & get_instance ();
Once an object is defined as a variable, you can replace $ this with the variable name:
$ CI = & get_instance ();
$ CI-> load-> helper ('URL ');
$ CI-> load-> library ('session ');
$ CI-> config-> item ('base _ url ');
Etc.
Note: You will notice that the get_instance () function is passed by reference:
$ CI = & get_instance ();
This is very important. assigning variables by referencing will use the original CodeIgniter object instead of creating a copy.
At the same time, please note: If you use php 4, it is best not to call get_instance () in the class constructor (). php4 has a problem when referencing the CI super object in the constructor, because the object exists only after the class is fully instantiated.
Http://www.bkjia.com/PHPjc/965015.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/965015.htmlTechArticlephp $ CI = get_instance ();, phpci beginner php to see someone write this, $ CI = get_instance (); to access the original CodeIgniter resources in your custom class library, you must use the get_instance () function...