Zend Framework:需要在 IIS7 上自动加载帮助
ZF 让我瘦了。如果不先使用它将其添加为资源,我就无法让 AutoLoader 的一个实例正常工作。
require_once ('Zend\Loader\Autoloader.php');
Zend_Loader_Autoloader::getInstance();
$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
'basePath' => APPLICATION_PATH . '/helpers',
'namespace' => 'Application_',
));
$resourceLoader->addResourceType('form', 'forms/', 'Form')
->addResourceType('functions', 'functions/', 'Functions')
->addResourceType('menus', 'menus/', 'Menu')
->addResourceType('acls', 'acls/', 'Acls');
现在我正在尝试加载一个插件,但当我知道文件存在时,ZF 会抱怨路径。
// located in application/controllers/plugins
require('controllers\plugins\Acl.php');
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new Application_Controller_Plugin_Acl($acl));
为什么我必须使用 require 这是 IIS7 的东西吗?我认为 AutoLoader 应该能处理好一切。
ZF is wearing me thin. I cannot get one instance of the AutoLoader to work without first using this to add it as a resource
require_once ('Zend\Loader\Autoloader.php');
Zend_Loader_Autoloader::getInstance();
$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
'basePath' => APPLICATION_PATH . '/helpers',
'namespace' => 'Application_',
));
$resourceLoader->addResourceType('form', 'forms/', 'Form')
->addResourceType('functions', 'functions/', 'Functions')
->addResourceType('menus', 'menus/', 'Menu')
->addResourceType('acls', 'acls/', 'Acls');
Now I am trying to load a plugin but ZF complains about the paths when I know the files exist.
// located in application/controllers/plugins
require('controllers\plugins\Acl.php');
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new Application_Controller_Plugin_Acl($acl));
Why do I have to use require Is this a IIS7 thing? I thought the AutoLoader was supposed to take care of everything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为这是 IIS 的问题。我认为这是对
Zend_Loader_Autoloader_Resource
的不当使用。您通过
Zend_Loader_Autoloader_Resource
告诉自动加载器添加命名空间Application
,并且它位于 basePathAPPLICATION_PATH 中。 '/helpers'
。如果我尝试的话:
ZF 应该在 APPLICATION_PATH 中找到它。 '/helpers/menus/Primary.php'。这真的是您想要找到该文件的地方吗?我猜不会。此外,尝试这样做:
Application_Controller_Plugin_Acl
将永远不会被包含,因为您缺少资源类型Controller_Plugin
及其在APPLICATION_PATH 内的目录。 '/helpers'
(我怀疑你想要那个)。我建议您一起删除
Zend_Loader_Autoloader_Resource
的使用,并将您的命名空间添加到应用程序的/library
目录中,并创建以下目录结构:然后,您需要添加 < code>/library 通过index.php 指向 PHP include_path 的路径。 (我认为这是标准的)
最后,将
Application
命名空间添加到您的application.ini
中:这应该可以解决您的问题。我建议你详细了解这个类的用途
Zend_Loader_Autoloader_Resource
。I don't think this is an IIS problem. I think this is a improper use of
Zend_Loader_Autoloader_Resource
.You're telling the autoloader via
Zend_Loader_Autoloader_Resource
to add the namespaceApplication
and that it is located in the basePathAPPLICATION_PATH . '/helpers'
.From this if I try:
ZF should find it in
APPLICATION_PATH . '/helpers/menus/Primary.php'
. Is that really where you want to find the file? I am guessing not. Further, trying this:Application_Controller_Plugin_Acl
will never be included cause your missing the resource typeController_Plugin
and it's directory insideAPPLICATION_PATH . '/helpers'
(I doubt you want that).I would suggest that you remove this usage of
Zend_Loader_Autoloader_Resource
all together and add your namespace into your application's/library
directory and create the following directory structure:Then, you need to add
/library
path to your PHP include_path via index.php. (I thought this was standard)Finally, add the
Application
namespace to yourapplication.ini
:That should clear up your problems. I suggest you learn more about the purpose of this class
Zend_Loader_Autoloader_Resource
.