CodeIgniter Forums

Full Version: How to create custom library in CodeIgniter?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
CodeIgniter libraries are collection of classes located in libraries folder(i.e, application/libraries and system/libraries). Libraries are used to make the collection of related methods. You can make as many libraries in CodeIgniter as per your convenience.
Let’s start the tutorial for create custom library in CodeIgniter. Visit here:- ... OP will provide real link, please ...
Considering that CI4 will be installed via composer: you can create your libraries without worrying about codeigniter methods and then upload your library to packagist. From within your codeigniter directory, composer require "companyName/yourLibrary" and then voila.

Your library file may start off like

PHP Code:
namespace MyCompanyName;

math {
 public function 
multiply($a 0$b 0) {
  return $a $b;

then in your controller file, you can do

PHP Code:
public function index() {
$object = new MyCompanyName\math;
$answer $object->multiply(45);

// code here to pass the variable $answer to the view