Zend Framework 2主题管理器

Mad*_*ort 1 zend-framework-mvc zend-framework2

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

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

主题管理器应该使用url params,例如?theme = lightTheme.主题在模块之外的文件夹"模板"中组织.主题还应包括视图脚本.

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

有没有人做得那么好或者能给我一些例子如何解决这个要求?

And*_*den 5

我认为这种模式可行...

主题文件夹结构

/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
Run Code Online (Sandbox Code Playgroud)

配置/ module.config.php

return array(
    'view_manager' => array(
        'template_path_stack' => array(
            '/path/to/themes',
        ),
    ),
);
Run Code Online (Sandbox Code Playgroud)

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);
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

//编辑:更改为使用route事件而不是controllerLoader