CodeIgniter Autoload

To autoload resources, open the application/config/autoload.php file and add the item you want loaded to the autoload array.

Important Points Of Autoload Concept

  1. This file specifies which systems should be loaded by default (OR) The files initialized automatically every time the system runs.
  2. Frequently used systems should be autoload instead of called at the local level repeatedly.
  3. Used to keep the framework as light-weight
  4. If your application needs global resource, make it autoload
  5. For example, the database is not connected to automatically since no assumption is made regarding whether you intend to use it. This file lets you globally define which systems you would like loaded with every request.

These are the things you can load automatically:

1. Libraries
2. Helper files
3. Custom config files
4. Language files
5. Models

Libraries

These are the classes located in the ‘application/libraries’ folder or in your application/libraries folder. $autoload option ‘libraries’ is a list of libraries that should be loaded. eg.database, session, e-mail, form validations etc.

$autoload['libraries'] = array();

Helper

These are the classes located in the ‘application/helper’ folder. $autoload option ‘helper’ is a list of helper collections that you will need to get work done. eg. URL, form, text helpers etc.

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

Config

These are the classes located in the ‘config’ folder. This item is intended for use ONLY if you have created custom config files. Otherwise, leave it blank.

$autoload['config'] = array();

Language

These are the classes located in the ‘system/language’ folder.

$autoload['language'] = array();

Model

These are the classes located in the ‘models’ folder. $autoload option ‘model’ allows you to autoload models.

$autoload['model'] = array();

Sample autoload.php configuration


$autoload['libraries'] = array('database','session','email','validation');
$autoload['helper'] = array('url','form','text','date','security'); 
$autoload['model'] = array(); 
$autoload['config'] = array();  

 

Leave a Reply

Your email address will not be published. Required fields are marked *