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}

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

posted @ 2022-05-05 17:23  亚索会代码  阅读(78)  评论(0编辑  收藏  举报