How you will use or load CodeIgniter libraries

How you will use or load CodeIgniter libraries

What is a library in codeigniter?

The most usable part of a codeigniter framework is its own libraries. which is use in to make any kind of project. It's provides a large set of libraries, which indirectly increase the speed of developing an application and easy to use set of classes. The library is located at core system/libraries. we just need to do is to load the library that we want to use. like email libraryform_validation library etc. also you can create Your Own Libraries.

Loading Library Syntax

    Use single library
    Use multiple library
    $this->load->library(array('email', 'form_validation')); 

Creating a New Library

If you want to create your own library then you should be placed in codeigniter application/libraries folder. you should follow step- 
  1. Your file name first character has to be in uppercase letter, like mylibaray.php
  2. Your class name first character must be in uppercase letter.
  3. our file name and class name should be same. so that we are not confused.
For create library class you have to go application/libraries. and suppose file name is Max2colors.php and class should be like this


class TestClass {
  function hello_world()
    return 'Welcome Hello World';
And if you want to use this on to controller then you have to write like this.
class Test extends CI_Controller
    function index()
        echo $this->max2colors->hello_world();