Creating your own library in CodeIgniter 4 is just as simple as in CI3 but the syntax has changed and there’s no documentation yet so here is my approach.
In CI3 your class has a basic prototype:
class Someclass {
public function some_method()
{
}
}
It goes into the /app/libraries
folder and is loaded in the controller:
$this->load->library('someclass');
Your class is now ready to be used.
In CodeIgniter 4, the path is similar: /app/Libraries
and your class needs a prototype with an namespace:
namespace App\Libraries;
class Someclass {
public function some_method()
{
}
}
You load it in your controller with:
$someclass = new \App\Libraries\Someclass();