This tutorial demonstrates, how to use third party libraries in Codeigniter. Codeigniter is capable to make any kind of websites like blogging websites,Informational Websites,Ecommerce Websites or social media websites, with any size. While developing web applications we will be dealing third party libraries. We cannot expect all of your favorite libraries are loaded in package manager, so only way to do it is directly including in the program.
In Codeigniter we have segmented 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.
In this example I used a third party image library php-image-resize. I downloaded from the given GitHub link.
Steps to integrate third party library to Codeigniter project
Step 1: Copy the downloaded third party script to the third_party folder
Step 2: Create a folder called imageResize inside the third_party folder. So your final path would be application/third_party/imageResize/imageResize.php
Step 3: Call this library in the construct function in your controller.
include APPPATH . 'third_party/imageResize/imageResize.php';
Step 4: I have called in a controller called Products.php.
Controller : Products.php
Below is the final snippet off the function usage in the Products.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Products extends CI_Controller { public function __construct() { parent::__construct(); include APPPATH . 'third_party/imageResize/ImageResize.php'; } public function image_resize() { $image = new \Eventviva\ImageResize($this->config->item('image_main').$fname); $image ->resizeToWidth(500,300) ->save($this->config->item('image_large').$fname) ->crop(100, 100) ->save($this->config->item('image_small').$fname) ; } }
Now you know how to access the third party library in Codeigniter.
You may be interested in reading below articles
Leave a Reply