Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load class/library in CodeIgniter?

Tags:

codeigniter

I have a library called lib, which contains a class called nusoap.php. I have put lib inside the folder application/libraries/.

When I try to load it, I'm getting the following error:

An Error Was Encountered
Unable to load the requested class: nusoap

This the code I use to load it

class Dealership extends Controller
{
    function Dealership()
    {
        parent::Controller();
        $this->load->library('nusoap.php');         
    }

}

Am I missing anything?

Thanks for helping

like image 954
Richard77 Avatar asked Sep 09 '26 15:09

Richard77


2 Answers

Non-existent class: xxx

Avoid use of namespaces

like image 131
CesareoAguirre Avatar answered Sep 12 '26 19:09

CesareoAguirre


  1. You dont need the .php extension in the $this->load->library() call

  2. The code igniter function that loads libraries does not (unfortunately) search the libraries directory recursively, so if you want to load libs in subfolders you need to do this:

    $this->load->library('lib/nusoap')

From the docs (Loader class):

Library files can be stored in subdirectories within the main "libraries" folder, or within your personal application/libraries folder. To load a file located in a subdirectory, simply include the path, relative to the "libraries" folder. For example, if you have file located at:

libraries/flavors/chocolate.php You will load it using:

$this->load->library('flavors/chocolate');

You may nest the file in as many subdirectories as you want.

like image 23
hammus Avatar answered Sep 12 '26 18:09

hammus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!