如何允许在 CakePHP 中自动加载自定义库?
您好,我正在使用 CakePHP,我需要将一些供应商文件添加到自动加载中。这是正确的方法吗:
在 bootstrap.php 中,我有以下代码:
function __autoload($className){
$classFile = '../vendors/phprtf/' . str_replace('_', '/', $className) . '.php';
// check if file exists
if(file_exists($classFile)) {
require $classFile;
}
}
PHPRTFLite 在各个子目录下有很多类文件。因此,列出所有这些并不是一个好的选择。
目前看来是有效的。
Hi I am using CakePHP and there are some Vendor files I need to add to the autoloading. Is this the correct method:
In the bootstrap.php, I have the following code:
function __autoload($className){
$classFile = '../vendors/phprtf/' . str_replace('_', '/', $className) . '.php';
// check if file exists
if(file_exists($classFile)) {
require $classFile;
}
}
The PHPRTFLite has a lot of class files under various sub directories. So listing all of them is not a good option.
It seems to be working for now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用
spl_autoload_register()
因为它提供的灵活性。You should use
spl_autoload_register()
for the flexibility it offers.