ThinkPHP自动填充实现无限级分类的方法
本文实例展示了ThinkPHP自动填充实现无限级分类的方法,是ThinkPHP常用功能之一,非常具有实用价值。现将完整实例分享给大家,供大家参考。具体实现步骤如下:
表aoli_cate如下图所示:
一、action部分:
aoli/Home/Lib/Action/CataAction.class.php文件如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
<?php class CateAction extends Action{ function index(){ $cate =M( 'cate' ); $list = $cate ->field( "id,name,pid,path,concat(path,'-',id) as bpath" )->order( 'bpath' )->select(); foreach ( $list as $key => $value ){ $list [ $key ][ 'count' ]= count ( explode ( '-' , $value [ 'bpath' ])); } $this ->assign( 'alist' , $list ); $this ->display(); } //添加栏目 function add(){ $cate = new CateModel(); if ( $vo = $cate ->create()){ if ( $cate ->add()){ $this ->success( '添加栏目成功' ); } else { $this ->error( '添加栏目失败' ); } //dump($vo); } else { $this ->error( $cate ->getError()); } } } ?> |
二、模型部分:
aoli/Home/Lib/Model/CataModel.class.php文件如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<?php class CateModel extends Model{ //对应数据库中的表aoli_cate protected $_auto = array ( array ( 'path' , 'tclm' ,3, 'callback' ), ); function tclm(){ $pid =isset( $_POST [ 'pid' ])?(int) $_POST [ 'pid' ]:0; echo ( $pid ); if ( $pid ==0){ $data =0; } else { $list = $this ->where( "id=$pid" )->find(); $data = $list [ 'path' ]. '-' . $list [ 'id' ]; //子类的path为父类的path加上父类的id } return $data ; } } ?> |
三、view视图部分
aoli/Home/Tpl/default/Cate/index.html页面如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
< form action = "__URL__/add" method = "post" > 请选择父级栏目:< select name = "pid" size = "20" > < option value = "0" >根栏目</ option > < volist name = "alist" id = "vo" > < option value = "{$vo['id']}" > < php > for($i=0;$i<$vo['count'];$i++){ echo ' '; } </ php > {$vo['name']} </ option > </ volist > </ select >< br /> 新的栏目名称:< input type = "text" name = "name" />< br /> < input type = "submit" value = "添加栏目" /> </ form > |
ThinkPHP自动填充实现无限级分类的方法的更多相关文章
- thinkphp中如何实现无限级分类?
thinkphp中如何实现无限级分类? 一.总结 1.数据表设计+递归算法 二.php实现无限级分类实例总结 1.数据库数据如下: 2.任务需求:给一个id,求自己和所有父亲. 3.实现代码如下:th ...
- thinkphp自动填充分析
thinkphp有一个自动填充字段的方法填充规则如下 array( array(完成字段1,完成规则,[完成条件,附加规则]), array(完成字段2,完成规则,[完成条件,附加规则]), .... ...
- Thinkphp的list_to_tree 实现无限级分类列出全部节点
list_to_tree 使用起来十分方便,具体可查看手冊.由于我在用的时候须要同一时候列出全部节点,所以写了一个递归函数,拿出来供大家參考. public function index(){ Loa ...
- Laravel 5.4 实现无限级分类
最近在工作中遇到一个需求,是要在laravel 5.4中实现无限级分类,但发现网上这个的资料较少,所以只能自己来实现了,下面这篇文章主要给大家介绍了关于在laravel 5.4中实现无限级分类的方法示 ...
- ThinkPHP 自动验证与自动填充无效可能的原因(转)
自动验证与自动填充是在使用ThinkPHP时经常用到的功能,但偶尔会遇到自动验证与自动填充无效的情况,本文就ThinkPHP 自动验证与自动填充无效可能的原因做一些分析. create() Think ...
- ThinkPHP 自动验证与自动填充无效可能的原因
原文链接:http://www.5idev.com/p-thinkphp_validate_auto_Invalid.shtml 自动验证与自动填充是在使用ThinkPHP时经常用到的功能,但偶尔会遇 ...
- EXCEL快速自动填充方法集锦
EXCEL快速自动填充方法集锦 原文地址,转载请注明:http://www.cnblogs.com/croso/p/5396841.html 方法一: 名称框输入a1:a1000回车,1, ctrl+ ...
- input框自动填充内容背景颜色为黄色解决方法
谷歌浏览器input自动填充内容,背景色会是黄色,想改的话: input:-webkit-autofill { box-shadow: 0 0 0px 1000px white inset;} 这种方 ...
- thinkphp实现无限级分类
普通的方法(采用for和foreach) //显示 foreach($data as $k=>$v){ //str_repeat()函数用于把字符串重复指定的次数 $data[$k]['titl ...
随机推荐
- powerbuilder webbrowser 内嵌浏览器 select下拉框无法使用
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MA ...
- DEDECMS爆严重安全漏洞
简要描述: 众所周知,因使用简单.客户群多,织梦CMS一直被爆出许多漏洞.“DEDECMS爆严重安全漏洞,近期官方会发布相关补丁,望大家及时关注补丁动态.” 详细说明: http://www.xx.c ...
- nagios系列教程地址
http://www.sosidc.com/sort/10/page/3 http://www.sosidc.com/sort/10/page/2 http://www.sosidc.com/sort ...
- .NET中的CTS、CLS、CLR
一.解释1 1.CLR(Common Language Runtime) :公共语言运行库 CLR 是CTS(Common Type System:通用类型系统)的实现, 即是说:CLR是应用程序的执 ...
- [Flutter] Creating, Importing & Using Dynamic Widgets from Other Files in a Flutter Application
In this lesson we’ll learn how to import widgets we’ve created in other files & use them in our ...
- [Typescript] Improve Readability with TypeScript Numeric Separators when working with Large Numbers
When looking at large numbers in code (such as 1800000) it’s oftentimes difficult for the human eye ...
- Rails生成随机字符串及加解密
1.生成安全的base64字符串 key = SecureRandom.urlsafe_base64
- Java8 更快的原子类:LongAdder(笔记)
更快的原子类:LongAdder 大家对AtomicInteger的基本实现机制应该比较了解,它们是在一个死循环内,不断尝试修改目标值,知道修改成功,如果竞争不激烈,那么修改成功的概率就很高 ...
- Zend Framework(一) windows8.1下配置zend framework1.12
windows8.1下配置zend framework1.12配置步骤: 1. 下载 zend framework1.12库 2. 创建zend frameworkproject 2 ...
- CentOS最常用命令
快捷键.常用命令: 文件和目录:# cd /home 进入 '/home' 目录# cd .. 返回上一级目录# cd ../.. 返回上两级目录# cd - 返回上次所在目录# cp file1 f ...