Conflict between Codeigniter AUtoload and Flourish Autoload functions

梦想的初衷 提交于 2019-12-04 19:22:12

I'm the author of Flourish. The example autoloader I provide on the getting started page is just supposed to help people get up and started if they don't have an environment already.

In your case since you have multiple libraries, I would recommend using spl_autoload_register(). You can register the CI autoloader and then register your Flourish one.

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

Thanks to http://codeigniter.com/forums/viewthread/73804/#366081 and some bits of information from some CI folk that I follow on twitter (I asked em): Eric Barnes, Dan Horrigan, Phil Sturgeon and Zack Kitzmiller, I found a solution. If you are a CodeIgniter n00b like me, you may like to follow these guys.

I deleted init.php and config.php, then jammed the following into the bottom of my CI's config.php (I am also autoloading from a custom library called 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');

Works brilliantly. Thanks, people!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!