Builtin Libraries
Library

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('email');
$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

$this->load->library('email');
$this->email->to('youremail@xyz.com');

where email is library

Email Library

We use this Library to send email.

Code

$this->load->library('email');
$this->email->from('your@xyz.com', 'Your Name');
$this->email->to('your@xyz.com');
$this->email->cc('another@xyz.com');
$this->email->bcc('them@xyz.com');

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

$this->email->send();

Upload Library


Upload Library

We use this Library to upload file on server

Code

$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);
}
else
{
$data = array('upload_data' => $this->upload->data());

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


Previous
Next