Php $ CI = & amp; get_instance ();, phpci_PHP tutorial

Source: Internet
Author: User
Tags php for beginners
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.