新的 Zend_Loader_Autoloader 找不到文件
我刚刚从 ZF 1.7 升级到 ZF 1.9,几乎一切都工作正常......除了 Autoloader 之外。
旧:
require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();
新:
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('MySiteName_');
$loader->setFallbackAutoloader(true);
我需要自动加载的文件大多没有命名空间(因为它是来自预命名空间的大型项目)。它们位于以下目录中:
- /application/controllers
- /common/models
- /library
- /vendor
该网站似乎工作正常,除了找不到 /library/Form.php
以前可以,但现在不行了。如果我添加 require_once 'library/Form.php' 就可以了,但这不是必需的,而且我担心如果我在某些地方开始这样做,我将需要放弃自动加载器和硬编码全部包括。我认为添加“setFallbackAutoloader(true)”,并在我的包含路径中添加“library”可以修复它,但事实并非如此。
我的包含路径是:
.:/Users/lofye/Documents/htdocs/mysitename/vendor
:/Users/lofye/Documents/htdocs/mysitename/common
:/Users/lofye/Documents/htdocs/mysitename/common/models
:/Users/lofye/Documents/htdocs/mysitename/library
:/Users/lofye/Documents/htdocs/mysitename
非常感谢任何帮助!
I just upgraded from ZF 1.7 to ZF 1.9, and almost everything works fine... except for Autoloader.
Old:
require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();
New:
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('MySiteName_');
$loader->setFallbackAutoloader(true);
The files I need to auto-load are mostly not namespaced (because it's a large project from pre-namespacing). They are in the following directories:
- /application/controllers
- /common/models
- /library
- /vendor
The site seems to work fine EXCEPT that it can't find /library/Form.php
It used to be able to, but not anymore. It works if I add a require_once 'library/Form.php', but that shouldn't be necessary, and I'm worried that if I start doing that in some places, I'll need to abandon the autoloader and hard-code all includes. I thought adding "setFallbackAutoloader(true)", combined with having "library" in my include path would fix it, but it didn't.
My include path is:
.:/Users/lofye/Documents/htdocs/mysitename/vendor
:/Users/lofye/Documents/htdocs/mysitename/common
:/Users/lofye/Documents/htdocs/mysitename/common/models
:/Users/lofye/Documents/htdocs/mysitename/library
:/Users/lofye/Documents/htdocs/mysitename
Any help greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的自动加载器只会尝试加载以
MySiteName_
开头的类。尝试添加Form
作为命名空间吗?Your autoloader is only going to attempt loading classes that begin with
MySiteName_
. Try addingForm
as a namespace maybe?你说如果你这样做的话它会起作用:
但是,如果包含你的库路径,那么你应该像自动加载器一样指定,如下所示:
尝试输入 require_once 'Form.php';到你的脚本中。它会爆炸吗?然后,您的包含路径没有 /library,这需要修复。
You said it works if you do this:
But, if your library path is included, then you should be specifying, as autoloader does, like this:
Try typing require_once 'Form.php'; into your script. Does it bomb? Then, your include path doesn't have /library, and that would need to be fixed.
文件
library/Form.php
中的类名称应该是Form
。你的班级名称是什么?我在这里测试过并且工作正常。
The class name inside the file
library/Form.php
should beForm
. What's your class name?I tested here and is working fine.