0

我想在 Zend Framework 中使用控制器插件。我在应用程序文件夹中创建了一个文件夹“插件”,并在其中创建了一个文件 Test.php。它的内容:

<?php

class Plugin_Multilanguage extends Zend_Controller_Plugin_Abstract{
    public function preDispatch(){
        echo 'The plugin is working';
    }
}

在 Bootstrap 文件中,我添加了功能:

protected function _initAutoload(){


        $fc = Zend_Controller_Front::getInstance();
        $fc->registerPlugin(new Plugin_Multilanguage());


    }

它不起作用。我什至没有任何错误或磨损。只是一个空白页。我注意到有很多类似的主题,我已经阅读了所有这些主题,但我仍然对这个简单的问题感到困惑。我使用 Zend Framework 1.11。请帮忙。

我收到以下错误:

 Fatal error: Class 'Plugin_Multilanguage' not found in C:\zendSites\moduleDeveloper\application\Bootstrap.php on line 13

我的 application.ini 文件内容:

[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.view[] =
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules = ""
resources.frontController.params.displayExceptions = 0
resources.frontController.params.prefixDefaultModule = "1"
resources.router.routes.defaultmodule.type = Zend_Controller_Router_Route_Module
resources.router.routes.defaultmodule.abstract = On    
resources.router.routes.defaultmodule.defaults.module = "system"
resources.router.routes.language.type = Zend_Controller_Router_Route
resources.router.routes.language.route = ":language"
resources.router.routes.language.reqs.language = "^(fr|en)$"
resources.router.routes.language.defaults.language = "en"
resources.router.routes.default.type = Zend_Controller_Router_Route_Chain
resources.router.routes.default.chain = "language, defaultmodule"
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

我尝试一一添加以下资源:

pluginPaths.Plugins = APPLICATION_PATH "/plugins"
autoloaderNamespaces[] = "plugins"
resources.frontController.plugins[] = "Plugin_Multilanguage"
pluginPaths.Plugins = APPLICATION_PATH "/plugins"
autoloaderNamespaces[] = "plugins"

只有错误消息在改变:

 Fatal error: Class 'Plugin_Multilanguage' not found in C:\zend\library\Zend\Application\Resource\Frontcontroller.php on line 117

我究竟做错了什么?

4

1 回答 1

0

应用程序可能无法读取您的插件路径:

APPLICATION_PATH "/plugins"

默认情况下,这些路径对于 ZF 中的类代码是不可读的。

尝试将您的插件移动到应用程序库:

/library
  /Application
    /Plugin
      Multilanguage.php

更新您的代码以反映这一点:

<?php

class Application_Plugin_Multilanguage extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch(){
        echo 'The plugin is working';
    }
}

并更新引导程序:

protected function _initAutoload()
{
    $fc = Zend_Controller_Front::getInstance();
    $fc->registerPlugin(new Application_Plugin_Multilanguage());
}
于 2013-02-12T03:22:42.273 回答