Sometimes, we might be required to make a custom library in the Codeigniter project. However, we can load the custom library quickly and use that functions.



Let's create a library file in the libraries folder of your app.


application/libraries/Mylibrary.php

<?php
    
class Mylibrary {
  function my_first_call()
  {

  // you can add any functionality here
    return 'Hello world!';
  }
    
} 
?>


Now let's create a controller and call the created custom library in Codeigniter


application/controllers/MyLibraryController.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
   
class MyLibraryController extends CI_Controller {
     
    /**
     * Get All Data from this method.
     *
     * @return Response
    */
    public function index()
    {
        $this->load->library('mylibrary');
        echo $this->mylibrary->my_first_call();
    }
}


then register route and see the output


application/config/routes.php

<?php

$route['my-library'] = "MyLibraryController";


Thanks, it will work for you.......