请问如何在Codeigniter中使用spl_autoload_register()?我需要这样做,因为我使用Codeigniter与另一个也使用自动加载的框架。在Codeigniter中使用PHP spl_autoload_register()
我在这里看到的东西
但我不知道如何定位的笨自动加载。我是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');
你是什么意思“目标CodeIgniter自动加载”?你想构建自己的自动加载器来加载CI类吗?或者你想要在CI自动加载器的旁边加载自己的类(如果有的话,我不知道)? – ircmaxell 2010-10-01 19:06:35
是的,ircmaxwell,我需要使用spl_autoload_register自动加载Codeigniter或其他框架(Flourish)。即如果一个类被调用,如果它没有在Flourish中找到,它将检查CI,反之亦然。目前,我在页面上收到异常错误“无法加载类”。但是,当我禁用任何一个自动加载,它运行良好。它是我需要的组合。你现在明白吗? – Cogicero 2010-10-01 19:56:14