Builtin Libraries

Library is collection of class, Library increase speed of the application.

In codeigniter there are two type of library

Built in libraries - Created by codeigniter, that is located in system/libraries.
User define libraries - User can create own library and save in application/libraries

Built libraries

Some mostly use libraries

Email Class
File Uploading Class
Form Validation
Input Class
Session Library
HTML Table Class
Shopping Cart Class

How to load Library

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

we can also load library by application/config/autoload.php

$autoload['libraries'] = array('database', 'email', 'session');

How to run Library


where email is library

Email Library

We use this Library to send email.


$this->email->from('your@xyz.com', 'Your Name');

$this->email->subject('Test Mail');
$this->email->message('Testing Message.');


Upload Library

Upload Library

We use this Library to upload file on server


$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 200;
$config['max_width'] = 800;
$config['max_height'] = 400;

$this->load->library('upload', $config);

if ( ! $this->upload->do_upload('userfile'))
$error = array('error' => $this->upload->display_errors());

$this->load->view('upload_form', $error);
$data = array('upload_data' => $this->upload->data());

$this->load->view('upload_success', $data);