Skip to content

Instantly share code, notes, and snippets.

@joshribakoff
Last active December 19, 2015 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshribakoff/5944175 to your computer and use it in GitHub Desktop.
Save joshribakoff/5944175 to your computer and use it in GitHub Desktop.
<?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