使用PHP spl_autoload_register()与笨
-
27-09-2019 - |
题
请我怎样才能使用spl_autoload_register()与笨?我需要,因为即时通讯使用笨与另一框架,它也使用自动加载做到这一点。
我看到的东西在这里。
但我不知道如何定位的笨自动加载。进出口新的OOP和笨。非常感谢!
上面的链路具有此:
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');
解决方案
由于 http://codeigniter.com/forums/viewthread/73804/#366081 和一些民间CI信息的一些位,我在Twitter(我问EM):埃里克·巴恩斯 ,丹霍里根,菲尔鲟和扎克基茨米勒,我找到了解决办法。如果你是一个笨的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');
出色的作品。谢谢,人!
其他提示
唉唉,我现在看到(看着现有问题后你问)......因为有2个定义__autoload
功能(并因此导致解析错误您所遇到的问题)......
要解决这个问题,只需重命名其中一个到别的东西,和定义呼叫spl_autoload_register('yournewfunctionname');
...
这应该是所有有给它,只要我理解您的问题...
不隶属于 StackOverflow