$result=$db->query(……);//这里查询得到结果集,注意结果集为数组
$tree= new Tree($result);
$arr=$tree->leaf(0);
$nav=$tree->navi(15);
$smarty->assign(‘arr',$arr);
$smarty->assign(‘nav',$nav);
$smarty->display(‘test.html');
在smarty模板中这样递归:
复制代码 代码如下:
<!--导航-->
<div>
<{foreach $nav as $n}>
<{if $n@iteration != $n@last}>
<{$n.name}> ->
<{else}>
<{$n.name}>
<{/if}>
<{/foreach}>
</div>
<!--树形菜单-->
<div>
<{function name=menu}>
<ul>
<{foreach $data as $entry}>
<li>
<span><{$entry.name}></span> <{*注意字段要改成自己的字段哦*}>
<{if isset($entry.child)}>
<{call name=menu data=$entry.child}>
<{/if}>
</li>
<{/foreach}>
</ul>
<{/function}>
<{call name=menu data=$arr}> <{*注意在这里$arr才是模板变量*}>
</div>
转载请申明来自kvoid.com