$categories = Category::find()->where(['parent_id' => $id, 'status' => '1'])->indexBy('id')->all();
$categoryIds = array_keys($categories);
$categoryIds[] = $id;
$products = Product::find()->where(['category_id' => $categoryIds, 'status' => '1'])->addOrderBy('id DESC');
<?php foreach ($categories as $one) {
echo '<h2>', $one->name; echo '</h2>';
foreach ($one->? as $prod) {
$prod->name;
}
}?>
public function actionStat()
{
$mass1 = Category::find()->asArray()->all();
$mass2= Price::find()->asArray()->all();
return $this->render('stat' , compact('mass1', 'mass2'));
}
<?php foreach ($mass1 as $item) :?>
<ul class="treeview">
<?php if ($item['id'] != 17): ?>
<li><a href="#"><?=$item['name']?> - 3</a>
<ul>
<?php foreach ($mass2 as $itemok) :?>
<?php if ($item['id'] == $itemok['category_id']): ?>
<li><a href="#"><?=$itemok['name']?></a></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</li>
<?php endif; ?>
</ul>
<?php endforeach; ?>