Home > Backend Development > PHP Tutorial > CodeIgniter configuration autoloadphp automatic loading usage analysis

CodeIgniter configuration autoloadphp automatic loading usage analysis

WBOY
Release: 2016-07-29 09:05:39
Original
936 people have browsed it

This article analyzes the automatic loading usage of autoload.php in CodeIgniter configuration. Share it with everyone for your reference, the details are as follows:

CodeIgniter has an automatic loading function, which can globally load class libraries, models, configurations, language packages, etc., which is very convenient for functions that need to be used globally.

For example: There is a global function written in app_helper.php. If you need to load this function globally, just set autoload.php:

Copy the code The code is as follows:

$autoload['helper'] = array ('app');


Next, all places can be used, the configuration, model and other configurations are similar. But while it is convenient, you also need to consider the disadvantages of this loading method.

If a project is divided into two parts, such as the front desk and the backend, is this function required for both the frontend and the backend? If there are different business modules for the front and backend, does each module need to be used?

If you need it, then it’s good to write it here. If you don’t need it, it’s not recommended to write it here.

Relevant class libraries and function calls should be loaded on demand

There are many ways to implement loading. You can load on a specified page, load in a public controller or function, and once loaded, it can be used globally. My common practice is to ignore the file and manually load global functions, etc.

Speaking of which, by the way, let’s talk about the loading mechanism of CI. The following is the loading method of class libraries, functions, etc.:

$this->load->library('session');
$this->load->model('hello_model');
$this->load->helper(array('url', 'array'));
$this->load->language(array('user_menu', 'user_tips'));

Copy after login

The loading method is unified and relatively simple to use, but it is a bit inconvenient to pass parameters when loading the class library. When loading the class library again, it will not be loaded again, but will be taken out from the saved static array. You need to pay attention to the status of the member attributes to prevent program exceptions because the values ​​still exist.

Readers who are interested in more related content about CodeIgniter can check out the special topics of this site: "Introduction to codeigniter tutorial" and "Advanced tutorial on CI (CodeIgniter) framework"

I hope that what is described in this article will be helpful to everyone's PHP program design based on the CodeIgniter framework. helped.

The above introduces the analysis of the autoloadphp automatic loading usage of CodeIgniter configuration, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

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