2

我有自定义前端控制器插件,它需要一些选项。此时我将它(插件)加载到 application.ini 文件中,如下所示:

resources.frontController.plugins.DynamicLayout = "My_Controller_Plugin_DynamicLayout"

此时我只有 option.ini 文件,然后使用 zend_config 导入它。有没有办法从 ZEND 的主 application.ini 文件中指定插件选项?也许是这样的?:

resources.frontController.plugins.DynamicLayout.test = "test_value"
4

1 回答 1

1

我使用类似这样的东西通过引导程序将信息传递给我的布局。

此示例适用于在不同域上运行的应用程序,因此具有不同的布局。(并且有一个单独的 MSIE 版本)。每个域作为一个单独的 application.ini

<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    protected function _initAutoload() {
        return new Zend_Application_Module_Autoloader(array(
            'namespace' => '',
            'basePath' => APPLICATION_PATH
        ));
    }

    // <snip> more _initMethods: Loggers, ACLs, ViewHelpers, etc. </snip>

    /**
     * Setup dynamic layout plugin
     *
     * @return Zend_Controller_Plugin_Broker
     */
    protected function _initFrontControllerLayoutPlugin() {
        // Ensure the front controller is initialized
        $this->bootstrap('FrontController');
        $front = $this->getResource('FrontController');

        $this->bootstrap('layout');
        $layout = $this->getResource('layout');

        // Set our Front Controller Plugin
        // !!!! right here I pass values to the layout
        // !!!! example layoutName, but you could pass anything you want...
        $plugin = new Plugin_DynamicLayout($layout, $this->getOption('layoutName'));

        return $front->registerPlugin($plugin);
    }

}

布局处理程序:

<?php

class Plugin_DynamicLayout extends Zend_Controller_Plugin_Abstract {

    private $layoutName;

    public function __construct(Zend_Layout $layout, $layoutName) {
        $this->layout = $layout;
        $this->layoutName = $layoutName;
    }

      public function preDispatch(Zend_Controller_Request_Abstract $request) {

        $layoutName = $this->layoutName;

        if (false !== strpos($request->getHeader('User-Agent'), 'MSIE')) {
            $layoutName = $layoutName . '-ie';
        }

        $this->layout->setLayout($layoutName);

    }
}

应用程序.ini:

[production]
layoutName = "Some_File_Name"
于 2011-01-06T05:33:46.250 回答