使用带有Codeigniter的PHP spl_autoload_register()

Cog*_*ero 1 php codeigniter autoload spl-autoload-register

请问如何在Codeigniter中使用spl_autoload_register()?我需要这样做,因为我使用Codeigniter与另一个框架也使用自动加载.

我在这看到的东西

PHP spl_autoload_register

我不知道如何定位CodeIgniter自动加载.我是OOP和Codeigniter的新手.非常感谢!

以上链接有:


function autoload_services($class_name){
    $file = 'services/' . $class_name. '.php';
    if (file_exists($file)){
        require_once($file);
    }
}

function autoload_vos($class_name){
    $file = 'vos/' . $class_name. '.php';
    if (file_exists($file)){
        require_once($file);
    }
}

function autoload_printers($class_name){
    $file = 'printers' . $class_name. '.php';
    if (file_exists($file)){
        require_once($file);
    }
}

spl_autoload_register('autoload_services');
spl_autoload_register('autoload_vos');
spl_autoload_register('autoload_printers');

Cog*_*ero 8

感谢http://codeigniter.com/forums/viewthread/73804/#366081以及我在Twitter上关注的一些CI民间的一些信息(我问他们):Eric Barnes,Dan Horrigan,Phil 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";
        }
    }
}
}
Run Code Online (Sandbox Code Playgroud)

spl_autoload_register( 'multi_auto_require');

工作出色.谢谢,人!