zend framework2 - ZF2: Get module name (or route) in the application layout for menu highlight -
how can in zf2 current (selected) module name in application layout? purpose: application layout include main menu of zf2 app, , every time module selected need highlight menu voice of module. need set correct route (url, action) when menu made for. every module has menu voice:
<ul class="nav"> <?php foreach ($menu_modules $mod): $is_active = ($mod['name'] == $current_module_name)?'selected':'';//get module name ?> <!-- class="active" --> <li><a href="#" <?php echo $is_active;?> ><?php echo $mod['title']; ?></a></li> <?php endforeach; ?> <li><a href="<?php echo $this->url('login/process', array('action'=>'logout')); ?>"><?php echo $this->translate('logout') ?></a></li> </ul> <div class="row-fluid" id="main_container"> <?php echo $this->content; ?> </div>
i know late answer question , there lot of answers available in case views question, may helpful.
in primary or module's module.php
, write -
class module { public function onbootstrap(mvcevent $e) { $sm = $e->getapplication()->getservicemanager(); $router = $sm->get('router'); $request = $sm->get('request'); $matchedroute = $router->match($request); $params = $matchedroute->getparams(); $controller = $params['controller']; $action = $params['action']; $module_array = explode('\\', $controller); $module = array_pop($module_array); $route = $matchedroute->getmatchedroutename(); $e->getviewmodel()->setvariables( array( 'current_module_name' => $module, 'current_controller_name' => $controller, 'current_action_name' => $action, 'current_route_name' => $route, ) ); } }
then can use $current_module_name
variable in layout file (as done in question itself). rest of variables mentioned in above code can used if required.
Comments
Post a Comment