php无限极分类以及递归(thinkphp)
php无限极分类:
无限极分类重点在于表的设计:
1在model中:
class CatModel extends Model{
protected $cat = array();
public function __construct(){
parent::__construct();
$this->cats = $this->select();
}
public function getTree($parent_id=0,$lev=0){
$tree = array();
foreach($this->cats as $c){
if ($c['parent_id'] == $parent_id) {
$c['lev'] = $lev;
$tree[] = $c;
//再查出下层的目录拼接到一起去
$tree = array_merge($tree,$this->getTree($c['cat_id'] , $lev+1));
}
}
return $tree;
}
}
2在controller中:
class GoodsController extends Controller{
public function catelist(){
$catModel = D('Cat');
$catlist = $catModel->getTree();
//print_r($catlist);
$this->assign('list',$catlist);
$this->display();
}
}
3在view中:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>管理中心 - 商品分类 </title>
<meta name="robots" content="noindex, nofollow" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="__PUBLIC__/Admin/styles/general.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/Admin/styles/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1> <span class="action-span"><a href="cateadd.html">添加分类</a></span> <span class="action-span1"><a href="#">管理中心</a> </span><span id="search_id" class="action-span1"> - 商品分类 </span>
<div style="clear:both"></div> </h1>
<form method="post" action="" name="listForm">
<div class="list-div" id="listDiv">
<table width="100%" cellspacing="1" cellpadding="2" id="list-table">
<tbody>
<tr>
<th>分类名称</th>
<th>商品数量</th>
<th>数量单位</th>
<th>导航栏</th>
<th>是否显示</th>
<th>价格分级</th>
<th>排序</th>
<th>操作</th>
</tr> <foreach name='catlist' item='cal'>
<tr align="center" class="0" id="tr_2">
<td align="left" class="first-cell" style="padding-left="1""> <img src="__PUBLIC__/Admin/images/menu_minus.gif" id="icon_0_1" width="9" height="9" border="0" style="margin-left:{$cal['lev']*2}em" /> <span><a href="#">{$cal['cat_name']}</a></span> </td>
<td width="10%">0</td>
<td width="10%"><span> </span></td>
<td width="10%"><img src="__PUBLIC__/Admin/images/no.gif" /></td>
<td width="10%"><img src="__PUBLIC__/Admin/images/yes.gif" /></td>
<td><span>0</span></td>
<td width="10%" align="right"><span>50</span></td>
<td width="24%" align="center"><a href="{:U('admin/cat/catedit',array('cat_id'=>$cal['cat_id']))}">编辑</a> | <a href="{:U('admin/cat/catdel',array('cat_id'=>$cal['cat_id']))}" title="移除">移除</a> </td>
</tr>
</foreach> </tbody>
</table>
</div>
</form>
<include file='./Index:footer' />
</body>
</html>
效果如下:
php无限极分类以及递归(thinkphp)的更多相关文章
- c# 菜单无限极分类-利用递归
表结构: 前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Web ...
- thinkphp 实现无限极分类
thinkphp实现无限极分类,获得所有的子类 今天学习测试了一上午也没有整出来,一开始一直没有办法把所有的子分类拿出来. 最后找到原因: 每次调用的时候没有在最后return的位置我没有选择retu ...
- php无限极分类递归与普通
1. 递归 public function getInfo(){$data=$this->select();$arr=$this->noLimit($data,$f_id=0,$level ...
- [thinkphp] 无限极分类
<?php /* * 无限极分类 类 */ header("Content-Type: text/html; charset=UTF-8"); Class Category ...
- php不使用递归实现无限极分类
无限极分类常用的是递归,但是比较不好理解,其实可以用数据库path,pid两个字段的设计来实现无限分类的功能 1.数据库设计 通过上图可以看出pid就是该栏目的父id,而path = 父path+pi ...
- PHP实现无限极分类的两种方式,递归和引用
面试的时候被问到无限极分类的设计和实现,比较常见的做法是在建表的时候,增加一个PID字段用来区别自己所属的分类 $array = array( array('id' => 1, 'pid' =& ...
- 夺命雷公狗ThinkPHP项目之----企业网站8之栏目的添加完善(无限极分类的完成)
我们刚才只是完成了添加的一部分,但是我们的上级分类也不能永远都是只有一个死的嘛,所以我们需要对她进行修改: 我们先将add方法里面的数据查出来再说: 然后在模板页进行遍历: 展示效果如下所示: 虽然是 ...
- thinkphp5.0无限极分类及格式化输出
首先我们来看数据表 从上图中可以发现,中国下有贵州,北京两个子节点,而北京有天安门一个子节点,纽约的子节点是"纽约的子类". 从pid为0看出,中国和纽约是顶级节点. 因为贵州的p ...
- js实现无限极分类
转载注明出处!!! 转载注明出处!!! 转载注明出处!!! 因为要实现部门通讯录,后台传来的数据是直接从数据库里拿的部门表,所以没有层级分类,只有parentId表示从属关系,所以分类的事情就交给我来 ...
随机推荐
- Gearman使用示例
最近的一个旧项目重构过程中,使用到了gearman这个开源项目,简单来讲,这是一个类似MQ的异步系统,一边派发任务,一边处理任务(有类似MQ中的消息发送方与接收方),目前支持java,php等多种语言 ...
- [LeetCode] Combination Sum IV 组合之和之四
Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...
- ElasticSearch第三步-中文分词
ElasticSearch系列学习 ElasticSearch第一步-环境配置 ElasticSearch第二步-CRUD之Sense ElasticSearch第三步-中文分词 ElasticS ...
- Ubuntu[1]安装Vesta Control Panel
参考:http://www.5013.org/archives/819 1)登录 ssh ubuntu@139.199.9.173 ubuntu@139.199.9.173's password: 重 ...
- go 常用包
标准的 Go 代码库中包含了大量的包,并且在安装 Go 的时候多数会伴随一起安 装.浏览 $GOROOT/src/pkg 目录并且查看那些包会非常有启发. fmt:包 fmt 实现了格式化的 I/O ...
- Oracle11g字符集AL32UTF8修改为ZHS16GBK详解
此问题发生在数据库迁移过程中.源数据库:自己笔记本上win7 64位系统的oracle11g个人版,字符集ZHS16GBK :目标数据库,HP的sqlserver2008 系统 64位数据库服务器,字 ...
- 移动端开发viewport深入理解(转)
一.viewport的概念 移动设备上的viewport就是设备的屏幕上能用来显示我们的网页的那一块区域,就是浏览器上用来显示网页的那部分区域,但viewport不局限于浏览器可视区域 的大小,它 ...
- Ubuntu14.04解决远程root-ssh拒绝登录
(1)查看ip地址是否冲突 我在单位的虚拟机ip地址是192.168.14.85,与其它机器冲突了.改成了192.168.14.83 (2)关闭Ubuntu14.04的防火墙 root@stgman- ...
- windows 10专业版14393.447 64位纯净无广告版系统 基于官方稳定版1607制作 更新于20161112
系统特点: 447更新日志(Win10 PC一周年更新正式版14393.447 32位/64位更新补丁KB3200970下载 Flash补丁Kb3202790下载): 1.通过网友的反馈,保留了Edg ...
- 后进先出 stack、 先进先出Queue
using System; using System.Collections; using System.Collections.Generic; using System.ComponentMode ...