0
votes

I want to get use of Controller plugins in Zend Framework. I've created a folder "plugins" in application folder and a file Test.php inside of it. It's content:

<?php

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

in the Bootstrap file, I have added function:

protected function _initAutoload(){


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


    }

And it doesn't work. I don't get even any kind of error or worning. Just a blank page. I have noticed that there plenty of similar topics, I've read all of them, but I'm still confused with that simple issue. I use Zend Framework 1.11. Please help.

I got following error:

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

My application.ini file content:

[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

I've tried to add one by one following resources:

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

Only the error message is changing:

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

What am I doing wrong?

1
Blank page means you have display_errors turned off. Check the server error log and consider turning errors on in development mode (which you can do in application.ini). - Tim Fountain
thank you, I'l edit my post with the errors that I get. - Andrei

1 Answers

0
votes

The chances are that your plugin path is not readable by the application:

APPLICATION_PATH "/plugins"

These kind of paths are not readable by default for class code in ZF.

Try moving your plugins to an Application library:

/library
  /Application
    /Plugin
      Multilanguage.php

Update your code to reflect this:

<?php

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

And update the bootstrap:

protected function _initAutoload()
{
    $fc = Zend_Controller_Front::getInstance();
    $fc->registerPlugin(new Application_Plugin_Multilanguage());
}