In this tutorial, we will learn about CodeIgniter autoload configuration. In the previous tutorial, we have practiced CodeIgniter database configuration and configure multiple database instances for a different working environment of the application.

As the name reflect the purpose, this file is used to initiate all that things which we need as default. Such as you want to use an Immortal to be loaded by default in the whole application you will declare that within this file.

It is recommended to only load those components which are essential for the application instead of all the components to be loaded in autoload.

The important point here is that autoload will frequently consume the loaded components and if you will declare them at the local scope that will consume up to that scope only. In this way, you can optimize the processing speed of your application.

CodeIgniter Autoload Components

Now we discuss what are the components which we can upload within this file, those components are declared below.

  • Libraries – it contains a list of libraries as an array which we will be fine to be loaded as default. Codeigniter libraries are very rich and supportive in application development. You can define any library as you are required in your application as a, separated value of Array as we have defined in the following code.
$autoload['libraries'] = array('database', 'session');
  • Drivers – drivers are the built-in feature of CodeIgniter application which will support the development. Even that you can develop your own Driver by extending the classes with “CI_Driver_Library”. In the following code, we are defining cache driver to be loaded as the default whenever application execute.
$autoload['drivers'] = array('cache');
  • Helper files – these are the extensive features of CodeIgniter support application for unique purposes. Such as for the improvement of payroll there is URL helper class which supports to developed clean URL paths. In the following code, we are defining that URL helper to be loaded as default.
$autoload['helper'] = array('url');
  • Custom config files – when you have created custom config files and you are wanted to load that file by default then you will define within the following array.
$autoload['config'] = array('paceconfig1', 'paceconfig2');
  • Language files – it is used to define the default language of the application. If your application is multilingual and supports multiple languages then you will declare each of that language within the following array. Remember that your language file must have postfix as “_lang.php” and you will not define this postfix within the array value.
$autoload['language'] = array('lang1', 'lang2');
  • Models – this is the most common open end of the CodeIgniter which can be considered as the data structure. It is used to exchange data between database and controller. It is the best practice to involve model within the exchange of data from the database to controller. By following the code you can define multiple models to be loaded as default to access them in the whole application.
$autoload['model'] = array('first_model', 'second_model');
Subscribe to our newsletter

You can unsubscribe anytime you want