I’m trying to create a multi level side navigation using kartik-v\yii2-sidenav
This is function code to generate the data from my model …
public static function getItems()
{
$items = [];
$parents = Menu::find()->where(['idparent' => 0])->all();
foreach($parents as $parent) {
$validate = Yii::$app->db->createCommand('select idParent from menu where idParent = '.$parent->id)->queryScalar();
if($validate != $parent->id)
{
$items[] = ['label' => $parent->label, 'url' => $parent->url, 'icon' => $parent->icon];
} else {
$items[] = ['label' => $parent->label, 'url' => $parent->url, 'icon' => $parent->icon, 'items' => [
Menu::getChild($parent->id)
]];
}
}
return $items;
}
and this is the function of getChild()
public static function getChild($id)
{
$items = [];
$childs = Menu::find()->where(['idParent' => $id])->all();
foreach($childs as $child)
{
$items[] = ['label' => $child->label, 'url' => $child->url, 'icon' => $child->icon];
}
return $items;
}
As for the parent , it is generated perfectly, but then child didnt…
I will attach the image , please help
Much Thanks…
My bad, my Db data is like this…
the label on the child should be payroll 1, payroll 2, payroll 3…