CodeIgniter configuration-autoload. php automatic loading Usage Analysis-php instance

Source: Internet
Author: User
Tags autoload codeigniter
This article mainly introduces the autoload of CodeIgniter configuration. the usage of php automatic loading is analyzed in detail based on the instance form. For more information about the principle and usage of the CodeIgniter automatic loading mechanism, see the example in this article to analyze the autoload of CodeIgniter configuration. php automatic loading usage. We will share this with you for your reference. The details are as follows:

CodeIgniter provides the automatic loading function to globally load class libraries, models, configurations, and language packs. It is quite convenient for global functions.

For example, if a global function is written in app_helper.php and needs to be loaded globally, you only need to set autoload. php:

The Code is as follows:

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


Next, you can use all the configurations, such as configuration and model. However, it is convenient to consider the disadvantages of this loading method.

If a project is divided into two parts, such as the foreground and background, is this function required? If there are different business modules in the front and back end, is it required for each module?

If you need it all, it is good to write it here. If you don't need it, it is not recommended to write it here.

Related class libraries and function calls should be loaded as needed

There are many ways to load data. You can load data on a specified page or in a public controller or function. Once load is enabled, it can be used globally. My common practice is to ignore this file and manually load global functions.

Let's talk about the CI loading mechanism. The following describes how to load class libraries and functions:

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

The loading method is uniform and easy to use, but it is inconvenient to pass parameters during the load class library. When the class library is loaded again, it will not be loaded again, but will be taken out from the saved static array. Pay attention to the status of member attributes to prevent program exceptions due to the existence of values.

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.