Class mdm\admin\components\MenuHelper

Inheritancemdm\admin\components\MenuHelper
Available since version1.0

MenuHelper used to generate menu depend of user role.

Usage

use mdm\admin\components\MenuHelper;
use yii\bootstrap\Nav;

echo Nav::widget([
   'items' => MenuHelper::getAssignedMenu(Yii::$app->user->id)
]);

To reformat returned, provide callback to method.

$callback = function ($menu) {
   $data = eval($menu['data']);
   return [
       'label' => $menu['name'],
       'url' => [$menu['route']],
       'options' => $data,
       'items' => $menu['children']
       ]
   ]
}

$items = MenuHelper::getAssignedMenu(Yii::$app->user->id, null, $callback);

Public Methods

Hide inherited methods

MethodDescriptionDefined By
getAssignedMenu() Use to get assigned menu of user. mdm\admin\components\MenuHelper
invalidate() Use to invalidate cache. mdm\admin\components\MenuHelper
parseRoute() Parse route mdm\admin\components\MenuHelper

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
CACHE_TAG 'mdm.admin.menu' mdm\admin\components\MenuHelper

Method Details

getAssignedMenu() public method

Use to get assigned menu of user.

array getAssignedMenu$userId$root null$callback null$refresh false )
$userId mixed
$root integer
$callback Closure

Use to reformat output. callback should have format like

function ($menu) {
   return [
       'label' => $menu['name'],
       'url' => [$menu['route']],
       'options' => $data,
       'items' => $menu['children']
       ]
   ]
}
$refresh boolean
invalidate() public method

Use to invalidate cache.

void invalidate( )
parseRoute() public method

Parse route

mixed parseRoute$route )
$route string