PHP教程

thinkphp 前后不分离模本递归分类

本文主要是介绍thinkphp 前后不分离模本递归分类,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

> 第一
> 创建两个视图方法

  //渲染出你所需要的递归的分类
  public function index(){
    $tree = ['id'=>'1','name'=>'名字1','pid'=>'0','_child'=>['id'=>'2','name'=>'名字2','pid'=>'1','_child'=>['id'=>'3','name'=>'名字3','pid'=>'2']];
    View::assign([
      'tree' => $tree
    ]);
    return View::fetch();
  }
  //递归包含页面
  //这里是模本哪里传递过来的参数赋值继续渲染
  public function tree($tree = null){
       View::assign('tree', $tree);
       return View::fetch('tree');
   }

> 前端
页面index,我这里是tp6,tp3有个R方法调用控制器

  {php} $model = new '你控制器的方法'; echo $model->tree($tree); //$tree是index赋值的{/php}

页面tree

  {volist name='tree' id='vo'}
    <tr>
      <td>{$vo.name}<td>
    </tr>
  {notempty name="vo._child"}
  {php}
      $model =  new '你控制器的方法';
      echo $model->tree($vo['_child']);
  {/php}    
  {/notempty}
  {/volist}

另外有大佬知道别的方法请告诉我,ლ(́◉◞౪◟◉‵ლ)感谢

这篇关于thinkphp 前后不分离模本递归分类的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!