codeigniter PHP Web Development

How to use third party library code in codeigniter

In this short article, I am going to explain the way to use third party libraries in Codeigniter 3. As it is well know Codeigniter is a very flexible MVC.

In Codeigniter, there is a folder called third_party in application folder. It is recommended to keep all your third party libraries in the third_party folder. So it will be very readable for all other developers working in your project.

To use third party libraries in Codeigniter 3 , You have to create a library that initialise the third party class:

For Example

In libraries folder under application folder create a file named myClass.php 

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MyClass
{
    public function __construct()
    {
        require_once APPPATH.'third_party/path/to/package/file.php';
    }
}

load the library in controller:

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

then you will be able to use the MyClass in any contoller of the application.

Leave a Reply

Your email address will not be published. Required fields are marked *


CAPTCHA Image
Reload Image