我正在使用 kohana 框架 3.1.2 并且我想要制作嵌套菜单...我正在使用 ORM_MPTT 类来处理我正在做的一切...在 View 中我正在获取数组,并且在这个数组中所有类别和子categoris 在一行中......如果我制作 foreach() 我得到这样的结果:
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
希望我描述正确... 我想要这样的结果:
<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>
非常感谢大家
最佳答案
您必须为每个子树递归调用渲染函数。只要有另一个子树,它就会输出另一个-list。
主视图.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>
如果您还希望您的 HTML 预期正确,您可以使用 $node->level() 函数。但这真的没有必要
关于css - kohana 框架 3.1.2 如何通过 Nested Sets 制作菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20342135/