How to create custom library file in CodeIgniter

In this post, I am going to explain “How to create custom library in CodeIgnitor”. CodeIgnitor has rich set of libraries which is located in “system/libraries”. Sometime we need some custom functionality for our requirement. Let’s see how to create custom own library in CodeIgnitor.

Create Custom Library

Step 1:- Go to application/libraries and create a new file Yourfilename_lib.php llike Mylibrary.php.




we can change above description according to requirement, Now create class with database connection and load pre-defined libraries.

If you want your libraries to be auto load always, the you can add your custom library in $autoload[‘libraries’] option array in config.php file.

Step 2:- If you want to load library in your controller then you can load library in controller file like

Step 3:- Now your library created and you can use your library method in controller like

 

I hope you might have understood it properly, keep reading our other blogs posts for more coding tricks.

Thanks!!

Add a Comment

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