1

我正在开发一个 Web 应用程序,使用 Codeigniter ( http://codeigniter.com/ ) 框架加上 Flourish 库 ( unframework ) ( http://flourishlib.com/ )。

我只是将繁茂文件夹放入我的应用程序,然后按照说明创建了一个繁茂初始化和配置文件(这些文件创建了 Flourish 自动加载)。

这是我的文件夹结构:

---auxcode\
--------init.php
--------config.php
--------flourish\
---system\
---application\
---公共_html\

init 文件只包含配置文件,配置文件内容如下所示:

function __autoload($class_name){

{
    // Customize this to your root Flourish directory
    $flourish_root = $_SERVER['DOCUMENT_ROOT'] . '/../auxcode/flourish/';

$file = $flourish_root . $class_name . '.php';

if (file_exists($file)) {
    include $file;
    return;
}

throw new Exception('The class ' . $class_name . ' could not be loaded');

}

在 public_html 中,索引文件已添加以下内容:

<?php include_once($_SERVER['DOCUMENT_ROOT'] . '/../inc/init.php');

现在,各自的自动加载功能(因为每个都有自己的)是冲突的。该应用程序仅在我注释掉任一框架的自动加载功能(及其依赖项)时才有效。

请问如何合并自动加载功能,以便我可以访问 CI 并以相同的方式蓬勃发展?

或者是否有更好的方法在一个应用程序中使用这两个系统?请说。

谢谢。

4

3 回答 3

4

我是《繁花似锦》的作者。我在入门页面上提供的示例自动加载器只是应该帮助人们在他们还没有环境的情况下起床和开始。

在您的情况下,由于您有多个库,我建议您使用spl_autoload_register()。您可以注册 CI 自动加载器,然后注册您的 Flourish 自动加载器。

于 2010-10-01T01:30:28.813 回答
2

Create a custom __autoload function. Rename the CI original into __autoload_ci and the Flourish __autoload_flourish.

It's important to add a return true; to both original autoloaders, when they were successful. Remove any errors/exceptions. Then deploy a custom wrapper:

 function __autoload($class) {
     __autoload_ci($class) || __autoload_flourish($class);
 }

Or use spl_autoload_register

于 2010-09-29T15:47:32.067 回答
1

感谢http://codeigniter.com/forums/viewthread/73804/#366081以及我在 Twitter 上关注的一些 CI 人员的一些信息(我问了他们):Eric BarnesDan HorriganPhil SturgeonZack Kitzmiller,我找到了解决方案。如果你和我一样是 CodeIgniter n00b,你可能会喜欢关注这些人。

我删除了 init.php 和 config.php,然后将以下内容塞进了我的 CI config.php 的底部(我还从一个名为 mylibrary 的自定义库中自动加载)。

function multi_auto_require($class) {
if(stripos($class, 'CI') === FALSE && stripos($class, 'PEAR') === FALSE) {
    foreach (array('flourish', 'mylibrary') as $folder){
        if (is_file(APPPATH."../auxengines/{$folder}/{$class}.php")){
            include_once APPPATH."../auxengines/{$folder}/{$class}.php";
        }
    }
}
}

spl_autoload_register('multi_auto_require');

工作出色。谢谢,人们!

于 2010-10-04T09:55:39.033 回答