Let's take a look at the specific question first.
Adding roles is part of the role menu, how do you make the role menu selected when you perform the add role?
Adminlte left navigation Create,view etc. action cannot be positioned to index module (left level two navigation cannot be positioned)
If you follow our previous tutorial, then the next question should not be a problem, first to see how we handled the menu on the left side of the
Use Mdm\admin\components\menuhelper; <?php $callback = function ($menu) { //due to space limitations, the code here is omitted, the source is found in the original text};//Here we have optimized the Echo Dmstr\widgets\menu for the menu we started writing: : Widgets ([ ' options '] = [' class ' = ' Sidebar-menu '], ' Items ' = Menuhelper::getassignedmenu (yii::$ App->user->id, NULL, $callback),]);?>
See here, we might as well open the file Dmstr\widgets\menu see here is how to implement the left menu to select this problem that bothers many classmates.
protected function Isitemactive ($item) {if (Isset ($item [' url ']) && is_array ($item [' url ']) && isset ($ item[' URL '][0])) { //... if ($arrayRoute [0]!== $arrayThisRoute [0]) { return false; } if (Isset ($arrayRoute [1]) && $arrayRoute [1]!== $arrayThisRoute [1]) { return false; } if (Isset ($arrayRoute [2]) && $arrayRoute [2]!== $arrayThisRoute [2]) { return false; } //...... return true; } return false;}
Look, look at the code above, that is, the left menu is activated when the current route is exactly equal to the menu route when the menu is activated.
In view of the many small partners we talked about at the beginning of the two questions, we only need to slightly adjust the code, to control the controller and not the action, but the source file we can not modify, how to do? It's hot, salad.
Here we copy the dmstr\widgets\menu.php file to backend\components\menu.php, and then modify the Isitemactive method as follows
protected function Isitemactive ($item) {if (Isset ($item [' url ']) && is_array ($item [' url ']) && isset ($ item[' URL '][0])) { //... Overrides the rules for routing, whether the controller is highlighted and not the action $routeCount = count ($arrayRoute); if ($routeCount = = 2) { if ($arrayRoute [0]!== $arrayThisRoute [0]) { return false; } } elseif ($routeCoun t = = 3) { if ($arrayRoute [0]!== $arrayThisRoute [0]) { return false; } if (Isset ($arrayRoute [1]) && $arrayRoute [1]!== $arrayThisRoute [1]) { return false; } } else { C15/>return false; } if ($arrayRoute [0]!== $arrayThisRoute [0]) { // return false; } //if (Isset ($arrayRoute [1]) && $arrayRoute [1]!== $arrayThisRoute [1]) { // return false;< c24/>//} //if (Isset ($arrayRoute [2]) && $arrayRoute [2]!== $arrayThisRoute [2]) { // return false; // } //...... return true; } return false;}
Now that we're done, the menu file on our left-hand side changes its point to Backend\components\menu
Go ahead and try our problem solving.