Zend 框架。如何将选项传递给自定义前端控制器插件?

发布于 2024-10-10 17:56:09 字数 373 浏览 8 评论 0原文

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

resources.frontController.plugins.DynamicLayout = "My_Controller_Plugin_DynamicLayout"

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

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

I have custom front controller plugin that takes some options.
At this time I load it (plugin) in application.ini file like this:

resources.frontController.plugins.DynamicLayout = "My_Controller_Plugin_DynamicLayout"

At this time I just have option.ini file and then use zend_config to import it.
Is there a way to specify plugin options from ZEND's primary application.ini file?
Maybe something like this?:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

再见回来 2024-10-17 17:56:09

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

此示例适用于在不同域上运行的应用程序,因此具有不同的布局。 (并且有一个单独的 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);
    }

}

布局Handler:

<?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);

    }
}

application.ini:

[production]
layoutName = "Some_File_Name"

I use something like this to pass info to my layouts using bootstrap.

This example is for an application that runs on different domains, thus different layouts. (and has a separate version for MSIE). Each domain as a separate 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);
    }

}

The layout Handler:

<?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);

    }
}

The application.ini:

[production]
layoutName = "Some_File_Name"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文