Zend Framework:需要在 IIS7 上自动加载帮助

发布于 2024-11-25 19:43:17 字数 946 浏览 1 评论 0原文

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

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

发布评论

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

评论(1

往日情怀 2024-12-02 19:43:17

我不认为这是 IIS 的问题。我认为这是对 Zend_Loader_Autoloader_Resource 的不当使用。

您通过 Zend_Loader_Autoloader_Resource 告诉自动加载器添加命名空间 Application ,并且它位于 basePath APPLICATION_PATH 中。 '/helpers'

如果我尝试的话:

new Application_Menu_Primary();

ZF 应该在 APPLICATION_PATH 中找到它。 '/helpers/menus/Primary.php'。这真的是您想要找到该文件的地方吗?我猜不会。此外,尝试这样做: Application_Controller_Plugin_Acl 将永远不会被包含,因为您缺少资源类型 Controller_Plugin 及其在 APPLICATION_PATH 内的目录。 '/helpers' (我怀疑你想要那个)。

我建议您一起删除 Zend_Loader_Autoloader_Resource 的使用,并将您的命名空间添加到应用程序的 /library 目录中,并创建以下目录结构:

/library/Application/Controller/Plugin/Acl.php
/library/Application/Form/
...etc

然后,您需要添加 < code>/library 通过index.php 指向 PHP include_path 的路径。 (我认为这是标准的)

set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

最后,将 Application 命名空间添加到您的 application.ini 中:

autoloaderNamespaces.app = 'Application'

这应该可以解决您的问题。我建议你详细了解这个类的用途 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 namespace Application and that it is located in the basePath APPLICATION_PATH . '/helpers'.

From this if I try:

new Application_Menu_Primary();

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 type Controller_Plugin and it's directory inside APPLICATION_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:

/library/Application/Controller/Plugin/Acl.php
/library/Application/Form/
...etc

Then, you need to add /library path to your PHP include_path via index.php. (I thought this was standard)

set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

Finally, add the Application namespace to your application.ini:

autoloaderNamespaces.app = 'Application'

That should clear up your problems. I suggest you learn more about the purpose of this class Zend_Loader_Autoloader_Resource.

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