How to use auto-loading resources in CodeIgniter
Home » BLOG » Web development » How to use auto-loading resources in CodeIgniter

How to use auto-loading resources in CodeIgniter

category:  CodeIgniter, Web development

if you are a web developer and familiar with the modern web framework, you may know the auto-load feature. CodeIgniter provides the auto-load feature that loads the libraries, helpers, packages, drivers, custom config files, language files, and models automatically every time the system runs.

The auto-load feature is useful when you need the specific resources available throughout your application.

Keep it in mind, you should load only the resources that you will need often in your application in the auto-load file. This way, you keep your application loading fast. The rest of the resources that you won’t need it often, you should load in the controllers where you will use.


In application/config/autoload.php, it is where you will load your resources. In the autoload.php, you will add the items you want to load to the autoload array. Of cause, with CodeIgniter, you will find the instructions there. Below is an example of setting the resources.

$autoload['libraries'] = array('session');
$autoload['helper'] = array('url');
$autoload['model'] = array('users','jobs');

For the example above, when I want to use the session library, URL helper or users and jobs models in the controller, I don’t need to load them, I just use them right away.

With CodeIgniter, you can learn and build your own web application quickly. CodeIgniter provides well-written documentation which is very helpful for the beginners. If you are new to CodeIgniter, you can learn it from here.