Class mdm\admin\components\MenuHelper
Inheritance | mdm\admin\components\MenuHelper |
---|---|
Available since version | 1.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
Method | Description | Defined 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
Constant | Value | Description | Defined By |
---|---|---|---|
CACHE_TAG | 'mdm.admin.menu' | mdm\admin\components\MenuHelper |
Method Details
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
|
$refresh | boolean |
Use to invalidate cache.
void invalidate( ) |
Parse route
mixed parseRoute( $route ) | ||
$route | string |