
TP5 foreach 2级(二级) 嵌套循环
发布日期:2021-05-04 09:23:16
浏览次数:32
分类:精选文章
本文共 3334 字,大约阅读时间需要 11 分钟。
例子:
学生模块
————学生管理
————添加学生
栏目模板
————管理栏目
用户模块
————用户管理
————权限管理
————分组管理
图标模块
————图标模块
系统设置
————学校模块
————后台首页
————合作单位
————上报教学站点
模板html代码:
{volist name="res" id="v"}TP5 控制器代码:{$v.title}{if condition="$v['child'] neq ''"}{volist name="v.child" id="v2"}{/volist}————{$v2.title}{/volist}{/if}
$res = Db::name('menu')->where('flid',1)->order('uid desc')->select(); foreach($res as $k => $v){ $res2 = Db::name('menu')->where("pid",$v['id'])->select(); $res[$k]['child'] = $res2; } $this->assign('res',$res);首先列出所有一级栏目,
再列出对应一级栏目的二级栏目
:http://blog.csdn.net/haibo0668/article/details/78464944
进阶例子:
$where = new Where; if($state){ $where['state'] = $state-1; } if($search){ $where['number'] = ['like', "%".$search."%"]; } $where['deleted'] = 0; $where['user_id'] = $Session['user_id']; $list = Db::name('order') ->field('id,number,price,type,state,time,pay_time') ->where($where) ->order(['id' => 'desc']) ->paginate(10,false,['query' => request()->param(),'type' => 'page\Page','var_page' => 'page']); if(!empty($list)){ foreach($list as $k => $v){ $oprs = Db::name('order_product')->field('id,title,num,price,pid,controller,img')->where('number',$v['number'])->select(); if(!empty($oprs)){ foreach($oprs as $k2 => $v2){ if($v2['controller']=='Combination'){//组合 $p_list= Db::name('order_product_clist')->field('id,title,controller,price,img,type_mold,num,pid')->where('opid',$v2['id'])->select(); if(!empty($p_list)){ $cbrs=[]; foreach($p_list as $k3=> $v3){ // //$price31 +=$v3['price']; $cbrs[$k3]['id']=$v3['pid']; $cbrs[$k3]['title']=$v3['title']; // //$cbrs['price']=$v3['price']; $cbrs[$k3]['img']=$v3['img']?\app\admin\model\Common::file_url($v3['img']):$this->system_config['system_index_no_img']; if($v3['controller']=='Live'){ $ttt="直播"; }elseif($v3['controller']=='Video'){ $ttt="点播"; }elseif($v3['controller']=='Testpaper'){ $ttt="试卷"; }elseif($v3['controller']=='Shop'){ $ttt="商城"; }else{ $ttt="其它"; } $cbrs[$k3]['controller']=$v3['controller']; $cbrs[$k3]['type_title']=$ttt; } }else{ $cbrs=[]; } } if($v2['controller']=='Testpaper'){//试卷 试卷ID要加密 //$v2['id'] = 21; $v2['pid'] = model('index/CommonModel')->lock_url($v2['id'],'id'); }else{ $v2['pid'] =$v2['pid']; } if($v2['controller']=='Live'){ $type_title1='直播'; }elseif($v2['controller']=='Video'){ $type_title1='点播'; }elseif($v2['controller']=='Testpaper'){ $type_title1='试卷'; }elseif($v2['controller']=='Shop'){ $type_title1='商品'; }elseif($v2['controller']=='Combination'){ $type_title1='组合'; }else{ $type_title1='商品'; } $v2['type_title']=$type_title1; $v2['img'] =$v2['img']?\app\admin\model\Common::file_url($v2['img']):$this->system_config['system_index_no_img']; $v2['child'] =$cbrs; $oprs[$k2] = $v2; } }else{ $oprs=[]; } $v['child'] =$oprs; $list[$k] = $v; } }
出处:
发表评论
最新留言
表示我来过!
[***.240.166.169]2025年03月22日 17时57分59秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
QT :warning LNK4042: 对象被多次指定;已忽略多余的指定
2021-05-08
GLFW 源码 下载-编译-使用/GLAD配置
2021-05-08
针对单个网站的渗透思路
2021-05-08
Typescript 学习笔记六:接口
2021-05-08
【ASP.NET】ASP.NET中权限验证使用OnAuthorization实现
2021-05-08
02、MySQL—数据库基本操作
2021-05-08
OpenJDK1.8.0 源码解析————HashMap的实现(一)
2021-05-08
MySQL-时区导致的时间前后端不一致
2021-05-08
2021-04-05阅读小笔记:局部性原理
2021-05-08
go语言简单介绍,增强了解
2021-05-08
python file文件操作--内置对象open
2021-05-08
架构师入门:搭建基本的Eureka架构(从项目里抽取)
2021-05-08
Java核心技术及面试指南 流程控制方面的面试题答案
2021-05-08
MongoDB 快速扫盲贴
2021-05-08
修复搜狗、360等浏览器不识别SameSite=None 引起的单点登录故障
2021-05-08
EXTJS4.2——10.Tab+Iframe
2021-05-08
WEB基础——AJAX
2021-05-08
one + two = 3
2021-05-08
echart关系图平分节点删除时自动平衡问题
2021-05-08