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. Spring mvc

    1... . 2.spring 的结构图 3.spring mvc 架构 4.Spring mvc 的请求流程 . 文字讲解: request-------->DispatcherServler ...

  2. MFC画线功能总结

    本文仅用于学习交流,商业用途请支持正版!转载请注明:http://www.cnblogs.com/mxbs/p/6216464.html MFC画线功能要点有二:其一,鼠标按下时记录初始位置为线的起始 ...

  3. 理解 JavaScript 回调函数并使用

    JavaScript中,函数是一等(first-class)对象:也就是说,函数是 Object 类型并且可以像其他一等对象(String,Array,Number等)一样使用.它们可以"保 ...

  4. Dao跨事务调用实现转账功能

    1.首先在数据库当中创建数据库,并且创建它的 实现类 package com.beiwo.epet.entity; public class Account { private int id; pri ...

  5. APP逆向常识

    SO库Linux系统下的动态库文件,就像win系统下的dll文件一样.将APK,改成RAR,在Lib目录下.dex(classes.dex)Dex是Android系统中可以在Dalvik虚拟机上直接运 ...

  6. read properties

    读取配置文件在项目中使用频率很大,但是实际项目中各种人,各种用法,五花八门,往往是一种方式的各种变体,然很多种方式是其中一种方式的复杂化.今天我来总结下读取配置文件的集中方式及一些不能靠copy代码能 ...

  7. 给空签名包进行签名以及找不到keystore证书链问题的解决方案

    转 http://blog.csdn.net/u011106842/article/details/49683865

  8. json的场景应用与实战

    首先 要感谢慕课网的老师 地址:http://www.imooc.com/learn/68 下面我来开始总结: 什么是json的这些我就不多说了  不懂百度 <?php function cre ...

  9. celery使用方法

    1.celery4.0以上不支持windows,用pip安装celery 2.启动redis-server.exe服务 3.编辑运行celery_blog2.py !/usr/bin/python c ...

  10. layer.open打开iframe页面的调用父页面方法及关闭

    //调用父类方法 window.parent.exportData($('#shownum').val(),$('#splitstr').val()); //关闭iframe页面var index = ...