Last active
December 19, 2015 10:59
-
-
Save joshribakoff/5944175 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// in the config for any module, you can map routes to their appropriate layout | |
'route_layouts'=>array( | |
'home'=>'layout/layout-2col-left.phtml', | |
'category'=>'layout/layout-2col-left.phtml', | |
); | |
// A later module could override the previous configuration | |
'route_layouts'=>array( | |
'home'=>'layout/layout-custom.phtml', | |
); | |
// The dirty work - It hooks into the process and sets the current layout | |
/** Assign the layout for this route, based on the `route_layouts` key of the config */ | |
$e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function($e) { | |
$controller = $e->getTarget(); | |
$route = $e->getRouteMatch()->getMatchedRouteName(); | |
$config = $e->getApplication()->getServiceManager()->get('config'); | |
if (isset($config['route_layouts'][$route])) { | |
$controller->layout($config['route_layouts'][$route]); | |
} | |
}, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment