如何在CodeIgniter中加载类/库? [英] How to load class/library in CodeIgniter?

查看:76
本文介绍了如何在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.

这篇关于如何在CodeIgniter中加载类/库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆