【问题标题】:Zend Framework 2 Theme ManagerZend Framework 2 主题管理器
【发布时间】:2012-09-11 19:31:33
【问题描述】:

有关于 Zend Framework 2 的问题。 在我的应用程序中,我有一个模块可以处理我的整个应用程序。

为了进一步改进,我想开发一个主题管理器。

主题管理器应使用 ?theme = lightTheme 等 url 参数。 主题被组织在模块外的某个文件夹“模板”中。 主题还应包括视图脚本。

据我阅读一些 ZF2 文档所知,它可以通过一些侦听器事件来实现。

有没有人做的很好,或者可以给我一些例子,我是如何解决这个要求的?

【问题讨论】:

  • 我也听说过有关侦听器事件的信息。他们的意思是,在您的 Module.php 类中,您向应用程序注册了一个事件。然后,根据某些条件更改布局文件。当然,每个布局文件都是一个使用不同 CSS 文件的“主题”。我会尝试提供一个指向我在上面看到的网页的链接。

标签: zend-framework2 zend-framework-mvc


【解决方案1】:

我认为这种模式可以工作......

主题文件夹结构

/path/to/themes
/path/to/themes/some_theme
/path/to/themes/some_theme/layout.phtml
/path/to/themes/another_theme
/path/to/themes/another_theme/layout.phtml

config/module.config.php

return array(
    'view_manager' => array(
        'template_path_stack' => array(
            '/path/to/themes',
        ),
    ),
);

Module.php

namespace Something;

class Module
{
    public function onBootstrap(\Zend\EventManager\EventInterface $e)
    {
        $application = $e->getApplication();
        $em = $application->getEventManager();
        $em->attach('route', function($e) {

            // decide which theme to use by get parameter
            // $layout = 'some_theme/layout';
            // $layout = 'another_theme/layout';
            $e->getViewModel()->setTemplate($layout);
        });
    }
}

// 编辑:改为使用路由事件而不是controllerLoader

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-20
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    • 1970-01-01
    相关资源
    最近更新 更多