kohana framework 3.1.2 how make menu by Nested Sets

155 views Asked by At

I am using kohana framework 3.1.2 and i want make nested menu... I am using ORM_MPTT class for this everything i am doing correctly... in view i am getting array , and in this array all categoris and sub categoris are in one row... if i making foreach() i am getting result like this:

  cat1
  cat1_1
  cat1_2
  cat1_2_1
  cat1_2_2
  cat1_2_3
  cat1_3
  cat2
  cat3
  cat3_1
  cat3_2
  cat3_2_1
  cat3_2_2
  cat3_2_2_1
  cat3_2_2_2
  cat3_2_2_2_1
  cat3_2_2_2_2
  cat3_2_2_2_3
  cat3_2_3
  cat3_3
  cat4
  cat5

hope i describe everything correctly... I want result like this:

  <nav>
<ul>
    <li>Parent 1
        <ul>
            <li>Child 1</li>
               <li>Child 2
                  <ul>
                     <li>Child 2 1</li>
                     <li>Child 2 2</li>
                     <li>Child 2 3</li>
                  </ul>
                </li>
            <li>Child 3</li>
        </ul>
    </li>
    <li>Parent 2
        <ul>
            <li>Child 4</li>
            <li>Child 5</li>
            <li>Child 6</li>
        </ul>
    </li>
</ul>

thanks a lot of all

1

There are 1 answers

0
Matthias Lill On BEST ANSWER

You have to call a render function recursive for each subtree. As long as there is another subtree it will output another -list.

main_view.php

<?php echo new View('view2',array('node'=>$root_node)) ?>

view2.php

<ul>
    <?php foreach ($node->children() as $child):?>
        <li><?php echo $child->title?></li>
        <?php if ( ! $child->is_leaf()): ?>
            <?php echo new View('view2',array('node'=>$child)) ?>
        <?php endif; ?>
    <?php endforeach; ?>
<ul>

If you also want your HTML intended correct you can use the $node->level() function. But that is really unnecessary