将 PHP spl_autoload_register() 与 Codeigniter 结合使用
请问如何将 spl_autoload_register() 与 Codeigniter 一起使用?我需要这样做,因为我将 Codeigniter 与另一个也使用自动加载的框架一起使用。
我在这里看到了一些东西
但我不知道如何定位 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');
Please how can I use spl_autoload_register() with Codeigniter? I need to do this because Im using Codeigniter with another framework which also uses autoload.
I saw something here
but I dont know how to target the CodeIgniter autoload. Im new to OOP and Codeigniter. Thanks a lot!
The above link has this:
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');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢 http://codeigniter.com/forums/viewthread/73804/#366081以及我在 Twitter 上关注的一些 CI 人员提供的一些信息(我问他们):Eric Barnes,丹·霍里根,菲尔·斯特金< /a> 和 Zack Kitzmiller,我找到了解决方案。如果您是像我一样的 CodeIgniter n00b,您可能会喜欢关注这些人。
我删除了 init.php 和 config.php,然后将以下内容塞入 CI 的 config.php 底部(我还从名为 mylibrary 的自定义库自动加载)。
工作出色。谢谢大家!
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).
Works brilliantly. Thanks, people!
啊啊,我现在明白了(在查看之前的问题之后你问过)...你遇到了问题,因为有 2 个定义的 __autoload 函数(因此导致解析错误)...
要修复它,只需将其中一个重命名为其他名称,然后在定义之后调用
spl_autoload_register('yournewfunctionname');
...只要我理解你的问题,这应该就是全部内容了...
Ahhh, I see now (after looking at a prior question you asked)... You're having a problem because there are 2 defined
__autoload
functions (and hence result in a parse error)...To fix it, simply rename one of them to something else, and then right after definition call
spl_autoload_register('yournewfunctionname');
...That should be all there is to it, so long as I understand your problem...