CodeIgniter all of the available libraries are located in your system/libraries/ directory. In most CodeIgniter cases to use one of these classes involves initializing it within a controller using the following initialization method :

$this->load->library('class_name');

To load multiple libraries useing the following code :

$this->load->library(array('email', 'upload','table'));

Creating Your Own Libraries

It should be placed in application/libraries folder.

> File name first letter has to be in uppercase letter, like Mylib.php

> Class name first letter should also be in uppercase letter

> CodeIgniter File name and class name should be same.

Classes should have this basic prototype :

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Someclass {
    public function method_name()
    {

    }
}
?>

Loading Mylib.php

$this->load->library('mylib');

You can write library name in any one of the upper or lower case letter.

Once it is loaded, you can access your class using the lower case letter because object instances are always in lower case.

$this->mylib->method_name();

Utilizing CodeIgniter Resources within Your Library

To access CodeIgniter is native resources within your library use the get_instance() method. This method returns the CodeIgniter super object.

Frequently from within your control methods you will call any of the available CodeIgniter methods using $ this construct:

$this->load->helper('url');
$this->load->library('session');
$this->config->item('base_url');

$this, however, only works directly within your controllers, your models, or your views. If you would like to use CodeIgniter is classes from within your own custom classes you can do so as follows:

First, assign the CodeIgniter object to a variable:

$CI =& get_instance();

Once you’ve assigned the object to a variable, you’ll use that variable instead of $this:

$CI =& get_instance();

$CI->load->helper('url');
$CI->load->library('session');
$CI->config->item('base_url');

Extending Native Libraries

For example, to extend the native CodeIgniter Email class you’ll create a file named application/libraries/MY_Email.php, and declare your class with :

class MY_Email extends CI_Email {

}

Replacing Native Libraries

For example, to replace the native CodeIgniter Email library you’ll create a file named application/libraries/Email.php, and declare your class with :

class CI_Email {

}