codeigniter

How to use the CI libraries and helper?

Syntax#

  1. $this->load->library(‘library_name’);

  2. $this->library_name->function_name();

  3. $this->load->library(‘cart’); # for helper $this->load->helper(‘helperName’);

  4. $this->cart->insert($Array);

Creating and calling a library

In order to use libraries in CodeIgniter, you need to create a library.

class Pro {
  function show_hello_world()
  {
    return 'Hello World';
  }
}

In this library, which is called is pro.php, this file must be added to the following path.

Path: \xampp\htdocs\project\application\libraries

Now you can use it in your controller. Code to load this library in the controller:

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

Code to use the library functions:

class Admin extends CI_Controller {
    function index()
    {
        $this->load->library('pro');
        echo $this->pro->show_hello_world();
    }
}

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow