Custom Libraries
Create New Library

Create Library and save this application->libraires->mylibrary.php

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

class Mylibrary {

public function show() {
echo "This is show function";
}
}

Note:
Library class name start with capitalletter
File name same as class name also start with capitalletter

Load and Run Library

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

class User extends CI_Controller {

public function __construct() {
parent::__construct();
$this->load->library('mylibrary');
}

public function index()

$this->mylibrary->show();
}

}

Extend Library

We can extend codeigniter library.

Class MY_Cart extends CI_Cart {
----
----
Create own function
----
----
}

Where Cart is codeigniter library and Save these library under application/libraries

Replace Library

we can also replace codeigniter library.

Class CI_Cart {
----
----
Create own function
----
----
}

Where Cart is codeigniter library and Save these library under application/libraries


Previous
Next