Closed testt23 closed 5 years ago
Thank you for your question. In order for this issue tracker to be effective, it should only contain bug reports and feature requests.
We advise you to use our community driven resources:
This is an automated comment, triggered by adding the label question
.
You can iterate trough every children by accessing ->getChildren() in the item - its what your example actually does. Regarding bootstrap see bootstrap 4 documentations.
foreach($item->getChildren() as $sub) {
foreach($sub->getChildren() as $subSub) {
// etc.
}
}
I don't agree that this is the solution. on this logic if we have 10 sub menus we need 10 times to call foreach..
We need to find another solution together.
You can do something like this...
<?php
namespace app\helpers;
use Yii;
use luya\cms\menu\Item;
class MenuTreeHelper
{
public static function getTreeByNavItem(Item $item) {
$arr[] = $item;
foreach (Yii::$app->menu->getLevelContainer($item->depth+1, $item) as $it) {
$arr = array_merge($arr, MenuTreeHelper::getTreeByNavItem($it));
}
return $arr;
}
public static function getTreeByContainer($container) {
$arr=[];
foreach (Yii::$app->menu->findAll(['depth' => 1, 'container' => $container]) as $item):
$arr = array_merge($arr, MenuTreeHelper::getTreeByNavItem($item));
endforeach;
return $arr;
}
}
Like this you get an array by container: app\helpers\MenuTreeHelper::getTreeByContainer('default')
We could make helper methods for navigations/menu directly into luya cms.
BlockHelper::a($item, ['activeClass' => 'is_active']);
BlockHelper::list(Yii::$app->menu->find(), ['depth' => 3]);
I need help in my code as i am unable to create multi-level menu. Here is my code.
I want it to be the three level menu but currently it is showing only the level 2 menu.
example: menu 1 menu 2 menu 3 -- menu 3.1 -- menu 3.2 ----- menu 3.2.1 ----- menu 3.2.2 ----- menu 3.3.3 --------- menu 3.3.3.1 --------- menu 3.3.3.2 menu 4 menu 5 -- menu 5.1 -- menu 5.2 ---- menu 5.2.1