_php instance of autoload.php automatic load usage analysis of CodeIgniter configuration

Source: Internet
Author: User

In this paper, an example is given to analyze the autoload.php automatic loading usage of codeigniter configuration. Share to everyone for your reference, specific as follows:

CodeIgniter has the function of automatic loading, it can load class library, model, configuration, language pack and so on, it is quite convenient for the function that needs to be used globally.

For example: There is a global function written in app_helper.php that needs to be loaded globally, just set the autoload.php:

Copy Code code as follows:
$autoload [' helper '] = Array (' app ');

Next, all the places can be used, configuration, model and other configuration similar. But the convenience also needs to consider under this kind of loading method to have the malpractice.

If a project is divided into two pieces, such as the front desk, the background, that this function is the front and back of the table must be? If there are different business modules between the front and back, is it necessary to use each module?

If you need it, it's good to write here, if you don't need it, don't suggest it here.

For related class libraries, function calls should be loaded on demand

There are many ways to load, you can specify the page load, can be in the public controller, function inside the load, once load can be used globally. The common practice for individuals is to ignore the file, load global functions manually, and so on.

Speaking of which, by the way CI loading mechanism. The following are loading methods for class libraries, functions, and so on:

$this->load->library (' Session ');
$this->load->model (' Hello_model ');
$this->load->helper (Array (' URL ', ' array '));
$this->load->language (Array (' User_menu ', ' user_tips '));

The load way is unified, it is simpler to use, but the Load class library Shishun a bit inconvenient. The Load class library is not loaded again, but it is taken out of the saved static array, which requires attention to the state of the member property and prevents the program from being abnormal because of the value.

More readers interested in CodeIgniter-related content can view the site topics: "CodeIgniter Introductory Course" and "CI (CodeIgniter) Framework Advanced Course"

I hope this article will help you with the PHP program design based on CodeIgniter framework.

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.