4 уровневое меню, не могу сообразить как вывести 4 уровень?

Здравствуйте, сделал 3 уровня, пытался сделать 4 не смог. делал по примерам в инете, там было макс 3.
В php коде видно что сделан вывод 5 уровней.
А вот в html, проблема. там нужно дописать код я так понимаю чтобы 4 уровень выводился.

HTML
<ul class="sky-mega-menul sky-mega-menu-pos-left">
<?php foreach ($categories as $category):
if ($category['show_cat'] == '1'):
if (!isset($category['children']))
{
?>
<li><a href="/category/<?php echo $category['alias'] ?>/" title="<?= $category['name'] ?>"><?= $category['name'] ?></a></li>
<?
}
else
{
?>

<li aria-haspopup="true">
<?php $showChild = false; foreach ($category["children"] as $childfirst):
if ($childfirst['show_cat'] == '1')
{
$showChild = true;
}
break;
endforeach;
if ($showChild)
{
?>
<ul>
<?php foreach ($category["children"] as $childfirst):
if ($childfirst['show_cat'] == '1')
{
if (!isset($childfirst['children']))
{
?>
<li><a href="/category/<?= $childfirst['alias'] ?>/" title="<?= $childfirst['name'] ?>"><?= $childfirst['name'] ?></a></li>
<?
}
else
{
$showChilds = false;
foreach ($childfirst["children"] as $childsecond):
if ($childsecond['show_cat'] == '1')
{
$showChilds = true;
}
break;
endforeach;
if ($showChilds)
{
?>
<li class="parent">
<a href="/category/<?= $childfirst['alias'] ?>/" title="<?= $childfirst['name'] ?>"><?= $childfirst['name'] ?></a>
<? ?>
<div class="grid-container3">
<ul>
<?php foreach ($childfirst["children"] as $childsecond): ?>
<li><a href="/category/<?= $childsecond['alias'] ?>/" title="<?= $childsecond['name'] ?>"><?= $childsecond['name'] ?></a></li>
<? endforeach; ?>
</ul>
</div>
</li>
<?
}
else
{
?>
<li><a href="/category/<?= $childfirst['alias'] ?>/" title="<?= $childfirst['name'] ?>"><?= $childfirst['name'] ?></a></li>
<?
}
}
}
endforeach;
?>
</ul>
</li>

<?
}
?>
<?
}
endif;
endforeach;
?>
</ul>


PHP
$cats = ORM::factory('category')
                   ->order_by('position', 'ASC')
                   ->find_all();
$cilddel = array();
        foreach ($cats as $cat)
        {
            $data[$cat->id]['name'] = $cat->name;
            $data[$cat->id]['id'] = $cat->id;
            $data[$cat->id]['alias'] = $cat->alias;
            $data[$cat->id]['cattext'] = $cat->cattext;
            $data[$cat->id]['show_cat'] = $cat->show_cat;
            $data[$cat->id]['position'] = $cat->position;
            
            $ch1 = ORM::factory('category')
                      ->where('parent_id', '=', $cat->id)
                      ->order_by('position', 'ASC')
                      ->find_all();
            foreach ($ch1 as $c1)
            {
                $cilddel[$c1->id] = $c1->id;
                $data[$cat->id]['children'][$c1->id]['name'] = $c1->name;
                $data[$cat->id]['children'][$c1->id]['alias'] = $c1->alias;
                $data[$cat->id]['children'][$c1->id]['id'] = $c1->id;
                $data[$cat->id]['children'][$c1->id]['cattext'] = $c1->cattext;
                $data[$cat->id]['children'][$c1->id]['show_cat'] = $c1->show_cat;
                $data[$cat->id]['children'][$c1->id]['position'] = $c1->position;
                
                $ch2 = ORM::factory('category')
                          ->where('parent_id', '=', $c1->id)
                          ->order_by('position', 'ASC')
                          ->find_all();
                foreach ($ch2 as $c2)
                {
                    $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['name'] = $c2->name;
                    $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['alias'] = $c2->alias;
                    $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['id'] = $c2->id;
                    $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['cattext'] = $c2->cattext;
                    $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['show_cat'] = $c2->show_cat;
                    $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['position'] = $c2->position;
                    
                    $ch3 = ORM::factory('category')
                              ->where('parent_id', '=', $c2->id)
                              ->order_by('position', 'ASC')
                              ->find_all();
                    foreach ($ch3 as $c3)
                    {
                        $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['children'][$c3->id]['name'] =
                            $c3->name;
                        $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['children'][$c3->id]['alias'] =
                            $c3->alias;
                        $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['children'][$c3->id]['id'] = $c3->id;
                        $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['children'][$c3->id]['cattext'] =
                            $c3->cattext;
                        $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['children'][$c3->id]['show_cat'] =
                            $c3->show_cat;
                        $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['children'][$c3->id]['position'] =
                            $c3->position;
                        
                        $ch4 = ORM::factory('category')
                                  ->where('parent_id', '=', $c3->id)
                                  ->order_by('position', 'ASC')
                                  ->find_all();
                        foreach ($ch4 as $c4)
                        {
                            $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['children'][$c3->id]['children'][$c4->id]['name'] =
                                $c4->name;
                            $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['children'][$c3->id]['children'][$c4->id]['alias'] =
                                $c4->alias;
                            $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['children'][$c3->id]['children'][$c4->id]['id'] =
                                $c4->id;
                            $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['children'][$c3->id]['children'][$c4->id]['cattext'] =
                                $c4->cattext;
                            $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['children'][$c3->id]['children'][$c4->id]['show_cat'] =
                                $c4->show_cat;
                            $data[$cat->id]['children'][$c1->id]['children'][$c2->id]['children'][$c3->id]['children'][$c4->id]['position'] =
                                $c4->position;
                            
                            $ch5 = ORM::factory('category')
                                      ->where('parent_id', '=', $c4->id)
                                      ->order_by('position', 'ASC')
                                      ->find_all();
                            foreach ($ch5 as $c5)
                            {
                                $data[$cat->id]
                                ['children'][$c1->id]
                                ['children'][$c2->id]
                                ['children'][$c3->id]
                                ['children'][$c4->id]
                                ['children'][$c5->id]
                                ['name'] = $c5->name;
                                
                                $data[$cat->id]
                                ['children'][$c1->id]
                                ['children'][$c2->id]
                                ['children'][$c3->id]
                                ['children'][$c4->id]
                                ['children'][$c5->id]
                                ['alias'] = $c5->alias;
                                
                                $data[$cat->id]
                                ['children'][$c1->id]
                                ['children'][$c2->id]
                                ['children'][$c3->id]
                                ['children'][$c4->id]
                                ['children'][$c5->id]
                                ['id'] = $c5->id;
                                
                                $data[$cat->id]
                                ['children'][$c1->id]
                                ['children'][$c2->id]
                                ['children'][$c3->id]
                                ['children'][$c4->id]
                                ['children'][$c5->id]
                                ['cattext'] = $c5->cattext;
                                
                                $data[$cat->id]
                                ['children'][$c1->id]
                                ['children'][$c2->id]
                                ['children'][$c3->id]
                                ['children'][$c4->id]
                                ['children'][$c5->id]
                                ['show_cat'] = $c5->show_cat;
                                
                                $data[$cat->id]
                                ['children'][$c1->id]
                                ['children'][$c2->id]
                                ['children'][$c3->id]
                                ['children'][$c4->id]
                                ['children'][$c5->id]
                                ['position'] = $c5->position;
}
}
}
}
}

}
        
        foreach ($cilddel as $key => $item)
        {
            unset($data[$key]);
        }
  • Вопрос задан
  • 301 просмотр
Пригласить эксперта
Ответы на вопрос 2
SilenceOfWinter
@SilenceOfWinter
та еще зажигалка...
почитай про рекурсии, вообще для построения многоуровневых меню используется nested sets структура таблиц, для kohana есть модуль mptt.
Ответ написан
@karminski
Senior React.JS Developer
Я бы вам ответил: если у вас есть 4! уровня меню, вам надо пересмотреть структуру приложения.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы