新的 Zend_Loader_Autoloader 找不到文件

发布于 2024-08-13 23:27:49 字数 1081 浏览 15 评论 0原文

我刚刚从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只有一腔孤勇 2024-08-20 23:27:49

您的自动加载器只会尝试加载以 MySiteName_ 开头的类。尝试添加 Form 作为命名空间吗?

$loader->registerNamespace('Form');

Your autoloader is only going to attempt loading classes that begin with MySiteName_. Try adding Form as a namespace maybe?

$loader->registerNamespace('Form');
小嗲 2024-08-20 23:27:49

你说如果你这样做的话它会起作用:

require_once 'library/Form.php';

但是,如果包含你的库路径,那么你应该像自动加载器一样指定,如下所示:

require_once 'Form.php';

尝试输入 require_once 'Form.php';到你的脚本中。它会爆炸吗?然后,您的包含路径没有 /library,这需要修复。

You said it works if you do this:

require_once 'library/Form.php';

But, if your library path is included, then you should be specifying, as autoloader does, like this:

require_once 'Form.php';

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.

如果没有 2024-08-20 23:27:49

文件 library/Form.php 中的类名称应该是 Form。你的班级名称是什么?

我在这里测试过并且工作正常。

The class name inside the file library/Form.php should be Form. What's your class name?

I tested here and is working fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文