【问题标题】:Frontcontroller plugin does not loadFrontcontroller 插件不加载
【发布时间】:2010-12-04 00:19:00
【问题描述】:

当我在 zend frameworker 中使用前端控制器插件时,它似乎在自动加载器之前运行。我该怎么做?

在我的 app.ini 中

resources.frontController.plugins.routes = "Plugin_Routes"

插件/Routes.php

class Plugin_Routes extends Zend_Controller_Plugin_Abstract {
}

错误信息..

致命错误:在第 111 行的 /usr/share/php/Zend/Application/Resource/Frontcontroller.php 中找不到类“Plugin_Routes”

根本没有包含路径?

【问题讨论】:

    标签: zend-framework plugins front-controller


    【解决方案1】:

    我曾经有过:

    resources.frontController.plugins[] = "Dagho_Controller_Plugin_Auth"
    

    它对我的工作非常好

    更新:没有什么可看中的只是下面的这些行和学说自动加载器

    protected function _initAutoload() {
            $autoloader = new Zend_Application_Module_Autoloader(array(
                        'namespace' => 'Default',
                        'basePath' => dirname(__FILE__),
                    ));
    
            return $autoloader;
        }
    

    【讨论】:

    • 同样的效果.. 我认为它是一样的,除了你没有一个关联数组和一个额外的命名空间。你在引导程序中有什么东西可以首先加载自动加载器吗?
    • 哦,请您仔细检查一下权限!
    • 好吧,你让我找到了正确的方向:D 似乎命名空间是强加在插件上的......甚至手册也没有提到这一点:)
    【解决方案2】:

    是吗?

    plugins/Routes.php
    

    Zend 期望

    Plugin/Routes.php
    

    因为自动加载器会使用类名来找到正确的文件夹。

    My_Class_Something
    

    将是:

    My/Class/Something.php
    

    【讨论】:

    • 但这是 Zend 工具创建的目录...与模块 / 和控制器 / 是小写和复数相同,但在您的类名中,您使用大写和单数来制作它们 在错误消息中有甚至没有包含路径,这让我觉得在注册插件之前自动加载器还不存在。
    【解决方案3】:

    如果不起作用,请尝试使用自动加载器。

    在引导类中添加这段代码

    protected function _initBlablablaPlugin(){
    
        $autoloader = Zend_Loader_Autoloader::getInstance();
        //If your plugin is placed in the /library/My/Plugin/Blablabla, then register the "My_" namespace
        $autoloader->registerNamespace('My_');
    
        $frontController = Zend_Controller_Front::getInstance();
        $frontController->registerPlugin(new My_Plugin_Authorize());
    }
    

    【讨论】:

      【解决方案4】:

      好的,手册似乎有误或至少不清楚: http://framework.zend.com/manual/1.11/en/zend.controller.plugins.html

      缺少的是您需要应用程序命名空间,否则它将无法在 1.11 中工作

      app.ini

      resources.frontController.plugins.routes = "Application_Plugin_Routes"
      

      插件

      class Application_Plugin_Routes extends Zend_Controller_Plugin_Abstract { }
      

      会正常工作:)

      【讨论】:

        猜你喜欢
        • 2015-11-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-14
        • 2015-04-21
        • 1970-01-01
        • 2023-03-07
        • 1970-01-01
        相关资源
        最近更新 更多