Codeigniter Create custom library

Today, We want to share with you Codeigniter Create custom library.In this post we will show you how to use any library in codeigniter, hear for codeigniter load library in controller we will give you demo and example for implement.In this post, we will learn about How to create custom library file in codeigniter 3 with an example.

Codeigniter Create custom library

There are the Following The simple About Codeigniter Create custom library Full Information With Example and source code.

As I will cover this Post with live Working example to develop how to create plugin in codeigniter, so the create custom library codeigniter Directory structures for this example is following below.

Also Read :  CodeIgniter Login Registration Example Tutorial From Scratch

Create a CodeIgniter Libraries

Step 1:-Create Custom Library

first of all you Go to application/libraries as well as here create a new file Yourfilename_lib.php like as a Convertlibrary.php.

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source CodeIgniter application development framework for PHP 7.1 or newer
 *
 * @package     CodeIgniter
 * @author      pakainfo
 * @copyright           Copyright (c) 2021, pakainfo.
 * @license     
 * @link        https://pakainfo.com
 * @since       Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * pakainfo core CodeIgniter class
 *
 * @package     CodeIgniter
 * @subpackage          Libraries
 * @category            pakainfo
 * @author      pakainfo
 * @link        https://pakainfo.com
 */

CodeIgniter load pre-defined libraries

class Convertlibrary{
    private $CI;
    public function __construct()
    {
        $this->CI =& get_instance();
        $this->CI->load->helper('url');       
        $this->CI->load->database();
        
    }

   function show()
    {
        // Your main logic
    }
}

CodeIgniter load the library

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

Step 3: your library method in controller (In any controller)

$this->convertlibrary->show();

Web Programming Tutorials Example with Demo

Read :

Also Read :  PHP Get User IP Address

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Codeigniter Create custom library.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Reply

avatar
  Subscribe  
Notify of