Php 在Zend中包含模块插件

Php 在Zend中包含模块插件,php,zend-framework,plugins,Php,Zend Framework,Plugins,我编写了一个Auth插件来检查用户是否登录。除登录页面外,任何未登录的用户都不能访问应用程序中的任何内容 因此,我在文件application/modules/user/plugins/Auth.php中有这个: class User_Plugin_Auth extends Zend_Controller_Plugin_Abstract { public function preDispatch(Zend_Controller_Request_Abstract $request) {

我编写了一个Auth插件来检查用户是否登录。除登录页面外,任何未登录的用户都不能访问应用程序中的任何内容

因此,我在文件
application/modules/user/plugins/Auth.php
中有这个:

class User_Plugin_Auth extends Zend_Controller_Plugin_Abstract {
    public function preDispatch(Zend_Controller_Request_Abstract $request) {
        if (Zend_Auth::getInstance()->hasIdentity() 
               || $this->getRequest()->getActionName() == 'login') return;
        $request->setModuleName('user');
        $request->setControllerName('auth');
        $request->setActionName('login');
    }
}
然后我在
应用程序.ini中做了这个:

pluginPaths.User_Plugin = APPLICATION_PATH "/modules/user/plugins/"
resources.frontController.plugins[] = "User_Plugin_Auth"

但是,无论我如何移动
Auth.php
文件,也不管名称如何,我总是会遇到
致命错误:找不到类“User\u Plugin\u Auth”
。请帮帮我,我在这件事上浪费了一个多小时,真令人沮丧。

我认为问题在于文件名。我会尝试在这些位置创建文件的副本

application/modules/user/plugins/User_Plugin_Auth.php

application/modules/user/plugins/User/Plugin/Auth.php
当然,你只需要其中一个,所以一旦你找到一个有效的,就删除其他的

如果这对我配置中的语法没有帮助(Fam只是项目的代码名)

正如PHP5.3中的注释所指出的,假设配置了include路径,那么在旧版本中应该可以使用

resources.frontController.plugins.layout = "Fam_Controller_Plugin_Layout"
resources.frontController.plugins.route = "Fam_Controller_Plugin_Route"
哪些映射到我的库中的文件,例如

APPLICATION_PATH "/../library/Fam/Controller/Plugin/Layout.php"
为了在本项目中提供参考,我的Zend文件位于

APPLICATION_PATH "/../library/Zend"
因此,将文件调整到相对位置应该可以做到这一点

您的自动加载器是否已配置?我有 autoloaderNamespaces.0=“Fam”

你可能需要像这样的东西

autoloaderNamespaces[] = "User_"
resources.frontController.plugins.UserAuth = "User_Plugin_Auth"

这不是Zend2和PHP5.3的名称空间吗?我正在使用Zend1.1x和PHP5.3。。。如果您不使用名称空间,用uu替换\可能会奏效,对不起,我有点模糊-我很幸运,可以使用专用服务器工作,因此可以满足我对保持版本号的热爱-我将编辑我尝试了您在上面写的内容,没有任何效果。甚至有可能在
/library
文件夹之外有插件吗?还是相同的错误吗?是否已配置自动加载程序命名空间?如上所述,我刚刚在
/library
文件夹中制作了一个插件,现在它可以正常工作了。谢谢你的努力。
autoloaderNamespaces[] = "User_"
resources.frontController.plugins.UserAuth = "User_Plugin_Auth"