How to load class/library in CodeIgniter?

扶醉桌前 提交于 2020-01-05 02:23:38

问题


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


回答1:


  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.




回答2:


Non-existent class: xxx

Avoid use of namespaces



来源:https://stackoverflow.com/questions/20182724/how-to-load-class-library-in-codeigniter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!