TP5 foreach 2级(二级) 嵌套循环
发布日期:2021-05-04 09:23:16 浏览次数:32 分类:精选文章

本文共 3334 字,大约阅读时间需要 11 分钟。

例子:

学生模块

————学生管理

————添加学生

栏目模板

————管理栏目

用户模块

————用户管理

————权限管理

————分组管理

图标模块

————图标模块

系统设置

————学校模块

————后台首页

————合作单位

————上报教学站点

 

模板html代码:

{volist name="res" id="v"}
{$v.title}{if condition="$v['child'] neq ''"}{volist name="v.child" id="v2"}
————{$v2.title}
{/volist}{/if}
{/volist}

TP5 控制器代码:

$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;				}			}

 

出处:



上一篇:TP5 控制器Controller中URL,跳转和重定向
下一篇:PHP 判断时间是否为当天时间

发表评论

最新留言

表示我来过!
[***.240.166.169]2025年03月22日 17时57分59秒