I need to create custom libraries for my Codeigniter 3 application that have common functions used by all my custom library.
How to use function only in one place?
I need to create custom libraries for my Codeigniter 3 application that have common functions used by all my custom library.
How to use function only in one place?
You can create new custom libraries. The library classes created by you should be placed in your application/libraries folder.
Classes should have basic prototype like this (here the name Myclass as an example):
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Myclass {
public function my_function()
{
}
}
/* End of file Myclass.php */
From within any of your Controller functions you can initialize your class using the standard:
$this->load->library('myclass');
$this->myclass->my_function(); // Object instances will always be lower case