从Codeigniter中的新文件夹加载库

时间:2012-01-28 05:29:56

标签: php codeigniter-2

在我的应用程序中,我想从新文件夹加载库。 我的应用程序codeigniter。在我的根文件夹中有module文件夹,有一个库文件,我想在我的模型页面中加载该库。

这是我的代码:

$this->load->library('./modules/libraryname');  

当我加载库这段代码时,我收到了一条错误消息。

Unable load the requested library

我的代码中有什么错误。? 当我将库文件复制到codeigniter的库文件夹并将代码更改为:

 $this->load->library('libraryname'); 

然后它将加载库而不会出错。

但是我只需要从module文件夹中加载它。我该怎么办?

2 个答案:

答案 0 :(得分:0)

Codeigniter在应用程序/库中查找库,然后在系统/库中查找库。你只有这两个选项。文件夹是为此目的而给出的。

答案 1 :(得分:0)

此示例显示如何更改默认目录以更改类的扩展位置,特别是扩展Controller_CI - 我使用CH表示CHILD类<​​/ p>

在启动时:

if (is_dir('<path>/extend/codeigniter_CH/')) {
    define('APPEXTEND_PATH', '<path>/extend/codeigniter_CH/');
} else {
    exit("<br />Error<br /><br />Your application extend folder path:<br />" . APPEXTEND_PATH . "<br />does not appear to be set correctly. Please open the following file and correct this: " . SELF);
}

在Controller文件的第230行的Controller.php类(系统)中

if (file_exists(APPEXTEND_PATH . config_item('subclass_prefix') . 'Controller.php')) {
    require APPEXTEND_PATH . config_item('subclass_prefix') . 'Controller.php';
} else {
    exit("not found " . APPEXTEND_PATH . config_item('subclass_prefix') . 'Controller.php');

}