Richard77
Richard77

Reputation: 21671

How to load class/library in 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

Upvotes: 3

Views: 32046

Answers (2)

CesareoAguirre
CesareoAguirre

Reputation: 1607

Non-existent class: xxx

Avoid use of namespaces

Upvotes: 4

hammus
hammus

Reputation: 2612

  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.

Upvotes: 3

Related Questions