Home > Backend Development > PHP Tutorial > php $CI =& get_instance();, phpci_PHP tutorial

php $CI =& get_instance();, phpci_PHP tutorial

WBOY
Release: 2016-07-13 10:04:37
Original
1067 people have browsed it

php $CI =& get_instance();, phpci

See someone writing this for beginners, $CI =& get_instance();

To access the original resources of CodeIgniter in your custom class library, you must use the get_instance() function. This function returns a CodeIgniter super object.

Generally speaking, in your controller function you Any available CodeIgniter function can be called via $this:

$this->load->helper('url');
$this->load->library('session' );
$this->config->item('base_url');
etc.
$this, only directly affects your own controllers, models and views. When you When you want to use the original CodeIgniter class in a custom class, you can do this:

First, define the CodeIgniter object and assign it to a variable:

$CI =& get_instance();

Once you define an object as a variable, you can use that variable name instead of $this:

$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. By reference Assigning to a variable will use the original CodeIgniter object instead of creating a copy

Also, please note: If you use PHP 4, it is best not to call get_instance() in the constructor of the class. php4 has a problem referencing CI super objects located in constructors because the object does not exist until the class is fully instantiated.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/965015.htmlTechArticlephp $CI = get_instance();, phpci I am new to php and saw someone writing like this, $CI = get_instance(); To access the original resources of CodeIgniter in your custom class library, you must use the get_instance() function...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template