Thinkphp5無限級分類列表欄目的實現程式碼

語言: CN / TW / HK

一、前臺程式碼實現

                                      <table class="table table-bordered table-hover">
                                            <thead class="">
                                                <tr>
                                                    <th class="text-center" width=10%>ID</th>
                                                    <th>欄目名稱</th>
                                                    <th class="text-center">欄目型別</th>
                                                    <th class="text-center" width=20%>操作</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                {volist name="list" id="vo"}
                                                <tr>
                                                    <td align="center">{$vo.id}</td>
                                                    <td>{neq name="vo.level" value="0"}|{/neq}<?php echo str_repeat('-',$vo['level']*4) ?> {$vo.catename}</td>
                                                    <td align="center">{eq name="vo.type" value="1"}列表{else/}單頁{/eq}</td>
                                                    <td align="center">
                                                        <a href="{:url('cate/edit',array('id'=>$vo['id']))}"
                                                            class="btn btn-primary btn-sm shiny">
                                                            <i class="fa fa-edit"></i> 編輯
                                                        </a>
                                                        <a href="#"
                                                            onClick="warning('確實要刪除嗎', '{:url('cate/delete',array('id'=>$vo['id']))}')"
                                                            class="btn btn-danger btn-sm shiny">
                                                            <i class="fa fa-trash-o"></i> 刪除
                                                        </a>
                                                    </td>
                                                </tr>
                                                {/volist}
                                            </tbody>
                                        </table>
二、後臺實現程式碼:
在Cate.php中新增如下程式碼:
在Cate.php Model中定義的catetree()方法的實現 (用來完成無限級分類的顯示功能)
up-242111d0a9337c7b62d335746a054002a46.png