Frage

have on question about the Zend Framework 2. In my Application i have a module whiche handles my whole Application.

For further improvements i want to develop a Theme Manager.

The Theme Manager should work with url params like ?theme = lightTheme. The Themes are organized in a Folder "templates" somewehere outside the Module. The Themes should also include the view scripts.

As far as i know from reading some ZF2 documentations it could be achieved with some Listener Events.

Does anybody did that alright or can give me some example how ich can solve this requirement ?

War es hilfreich?

Lösung

I think this pattern could work...

themes folder structure

/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);
        });
    }
}

// edit: changed to use the route event instead of controllerLoader

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top