如何在CodeIgniter中加载类/库?

问题描述:

我有一个名为 lib 的库,其中包含一个名为 nusoap.php 的类。我已将lib放在文件夹 application / libraries / 中。

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

此我用来加载它的代码

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

}

我错过了什么吗?

感谢您的帮助


  1. $ this-> load-> library()调用中,您不需要 .php 扩展名

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

加载库的代码点火器函数不会(不幸地)递归搜索库目录,因此,如果要在子文件夹中加载库,则需要执行以下操作:

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')

来自文档(装载程序类)



库文件可以存储在主库文件夹中或您的个人应用程序/库
文件夹中的子目录。要加载位于子目录中的文件,只需包括相对于 libraries文件夹的
路径。例如,如果您有
文件位于以下位置:

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您将使用以下方式加载文件:

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.