How can I get in ZF2 the current (selected) module name in the application layout? Purpose: My application layout include the main menu of the zf2 app, and every time a module is selected I need to highlight the menu voice of the module. Also I need to set the correct route (url, action) when the menu is made with this for. Every module has a menu voice:
<ul class="nav">
<?php foreach ($menu_modules as $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 prefer easier way without dealing with
Module.php
Place this code into layout.phtml
I know its too late to answer this question and also that there are a lot of answers available already but just in case someone views this question, it may be helpful.
In the primary or any Module's
Module.php
, write this -Then you can use
$CURRENT_MODULE_NAME
variable in your layout file (as done in the question itself). The rest of the variables mentioned in the above code can be used if required.Use array_shift instead of array_pop (Kunal Dethe answer):