What is the correct way to dynamically create a menu using the "SideNav Widget" and 2 models the following:
category (id, description)
subcat (id, category_id, description)
Follow the desired structure:
<?php
echo SideNav::widget([
//'type' => SideNav::TYPE_DEFAULT,
//'heading' => 'Options',
'items' => [
[
'url' => '#',
'label' => 'Category One',
'items' => [
['label' => 'Sub-Category 1.1', 'url'=>'#'],
['label' => 'Sub-Category 1.2', 'url'=>'#'],
],
],
[
'label' => 'Category Two',
'items' => [
['label' => 'Sub-Category 2.1', 'url'=>'#'],
['label' => 'Sub-Category 1.1', 'url'=>'#'],
],
],
],
]);
?>
EDIT
The first loop in CATEGORY works fine.
$item = [];
$models = Category::find()->all();
foreach($models as $model) {
$item[] = ['label' => $model->description, 'url' => '#'];
}
How to make a loop (to get the subcat) within this other?