Using Rights generator component, we can easily create a dynamic menu, in which we scan every modules' controllers, to access the index page of them.
Put the following code into your views/layouts/main.php file.
<div id="mainMbMenu"> <?php $menuitems = array( array('label'=>'Home', 'url'=>array('/site/index')), array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')), array('label'=>'Contact', 'url'=>array('/site/contact')), ); $rightGenerator = new RGenerator(); $modules = array_keys(Yii::app()->getModules()); foreach ($modules as $module) { $module_menu = array(); $controllers = $rightGenerator->getControllersInPath(Yii::getPathOfAlias("application.modules.$module.controllers")); foreach ($controllers as $ctrl => $info) { $module_menu[] = array('label' => Yii::t($module, $info['name']), 'url' => array("/$module/" . lcfirst($info['name']))); } if (! empty($module_menu)){ $menuitems[] = array('url' => array("#$module"), 'label' => Yii::t($module, $module), "items" => $module_menu); } } $this->widget('ext.widgets.mbmenu.MbMenu',array( 'items'=> $menuitems, )); </div><!-- mainmenu -->
Total 2 comments
I too have encountered the same error The function "getControllersInPath" exist in the class RGenerator, but it's protected function. I have rewrite the declaration of function without . The code for mbMenu works. There is problem in this my operation ? Thanks
I was to try this but i have error :
RGenerator and its behaviors do not have a method or closure named "getControllersInPath".
Leave a comment
Please login to leave your comment.