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)的更多相关文章

  1. c# 菜单无限极分类-利用递归

    表结构: 前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Web ...

  2. thinkphp 实现无限极分类

    thinkphp实现无限极分类,获得所有的子类 今天学习测试了一上午也没有整出来,一开始一直没有办法把所有的子分类拿出来. 最后找到原因: 每次调用的时候没有在最后return的位置我没有选择retu ...

  3. php无限极分类递归与普通

    1. 递归 public function getInfo(){$data=$this->select();$arr=$this->noLimit($data,$f_id=0,$level ...

  4. [thinkphp] 无限极分类

    <?php /* * 无限极分类 类 */ header("Content-Type: text/html; charset=UTF-8"); Class Category ...

  5. php不使用递归实现无限极分类

    无限极分类常用的是递归,但是比较不好理解,其实可以用数据库path,pid两个字段的设计来实现无限分类的功能 1.数据库设计 通过上图可以看出pid就是该栏目的父id,而path = 父path+pi ...

  6. PHP实现无限极分类的两种方式,递归和引用

    面试的时候被问到无限极分类的设计和实现,比较常见的做法是在建表的时候,增加一个PID字段用来区别自己所属的分类 $array = array( array('id' => 1, 'pid' =& ...

  7. 夺命雷公狗ThinkPHP项目之----企业网站8之栏目的添加完善(无限极分类的完成)

    我们刚才只是完成了添加的一部分,但是我们的上级分类也不能永远都是只有一个死的嘛,所以我们需要对她进行修改: 我们先将add方法里面的数据查出来再说: 然后在模板页进行遍历: 展示效果如下所示: 虽然是 ...

  8. thinkphp5.0无限极分类及格式化输出

    首先我们来看数据表 从上图中可以发现,中国下有贵州,北京两个子节点,而北京有天安门一个子节点,纽约的子节点是"纽约的子类". 从pid为0看出,中国和纽约是顶级节点. 因为贵州的p ...

  9. js实现无限极分类

    转载注明出处!!! 转载注明出处!!! 转载注明出处!!! 因为要实现部门通讯录,后台传来的数据是直接从数据库里拿的部门表,所以没有层级分类,只有parentId表示从属关系,所以分类的事情就交给我来 ...

随机推荐

  1. 安装ArcGIS Engine 9.3

    本文仅用于学习交流,商业用途请支持正版!转载请注明:http://www.cnblogs.com/mxbs/p/6217003.html 准备: ArcGIS Engine 9.3.crack_for ...

  2. php 7.0 新特性

    php 7 主题是性能优化  SEO 之前版本:开发效率快,语言本身性能差 普通的php网站:IO密集型,瓶颈在mysql上,体现不出来php的性能劣势,在密集计算方面比C,C++,JAVA差几十倍甚 ...

  3. fopen函数和fread函数、fwrite函数

    fopen(打开文件) 相关函数 open,fclose 表头文件 #include<stdio.h> 定义函数 FILE * fopen(const char * path,const ...

  4. 让div盒子相对父盒子垂直居中的几种方法

    div相对于父盒子垂直居中的几种方法,之前在网上看到很多种方法,确实说的很对,也很具体,但是我感觉对于初学者来说,一目了然是最重要的,所以,我把很高深的技巧,和很复杂的css样式都剔除掉,旨在让更多人 ...

  5. 项目vue2.0仿外卖APP(七)

    ratings评价列表页实现 在ratings.vue组件里开发 首先先引入seller数据: 书写模板结构: 由于评价页又有之前写过的star.vue组件,所以又要在ratings.vue组件引入: ...

  6. [LeetCode] Delete Duplicate Emails 删除重复邮箱

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  7. 原生js实现fadein 和 fadeout

    js里面设置DOM节点透明度的函数属性:filter= "alpha(opacity=" + value+ ")"(兼容ie)和opacity=value/10 ...

  8. 启动Maven项目启动报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    tomcat在发布项目的时候没有同时发布maven依赖所添加的jar包,你需要设置一下eclipse:项目 -> 属性 -> Deployment Assembly -> Add - ...

  9. C++ 自由存储区是否等价于堆?

    "free store" VS "heap" 当我问你C++的内存布局时,你大概会回答: "在C++中,内存区分为5个区,分别是堆.栈.自由存储区.全 ...

  10. 在不损坏C盘的情况下为C盘扩容,适用于Win

    2016年12月29日14:29:27 参考原文:http://jingyan.baidu.com/article/90808022a6c6b7fd91c80fc8.html 在不损坏磁盘的情况下给某 ...