Articles → PHP CODEIGNITER → Create A Custom Library In Codeigniter

Create A Custom Library In Codeigniter






Example




  1. Create a new file inside the "libraries" folder.
  2. The name of the file is "MyLib.php" (you can give any name).
  3. Write the following code inside the file "MyLib.php"
  4. <?php
    class MyLib
    {
        public function MyFunc()
        {
            echo "Calling MyFunc";
        }
    
    }




  5. Now call the class inside the controller using the following code
  6. $this->load->library('mylib');
    
    $this->mylib->MyFunc();




Picture showing the output of calling the function from custom library

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Friday, July 24, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250