Thinkphp 获取所有子分类或父分类ID
/**
* @Author: HTL
* @Email: Huangyuan413026@163.com
* @DateTime: 2016-04-22 11:25:02
* @Description: 获取当前分类下所有子类ID
* @pid:父类ID
*/
function get_child_ids($pid){
return $this->__get_ids($pid,'','id');
}
/**
* @Author: HTL
* @Email: Huangyuan413026@163.com
* @DateTime: 2016-04-22 11:25:02
* @Description: 获取当前分类下所有父类ID
* @id:子类ID
*/
function get_parent_ids($id){
return $this->__get_ids($id,'','pid');
}
/**
* @Author: HTL
* @Email: Huangyuan413026@163.com
* @DateTime: 2016-04-22 11:25:02
* @Description: 获取类下所有父/子类ID
* @pid:多个父/子类ID集以,分隔
* @childids:找到的子/父分类列表
* @find_column:where查找的字段[id|pid:default]
*/
function __get_ids($pid,$childids,$find_column = 'id'){
if(!$pid || $pid<=0 || strlen(pid)<=0 || !in_array($find_column,array('id','pid'))) return 0;
if(!$childids || strlen($childids)<=0) $childids = $pid;
$column = ($find_column =='id'? "pid":"id");//id跟pid为互斥
$ids = $this->model->where("$column in($pid)")->getField("$find_column",true);
$ids = implode(",",$ids); //未找到,返回已经找到的
if($ids<=0) return $childids;
//添加到集合中
$childids .= ','.$ids;
//递归查找
return $this->__get_ids($ids,$childids,$find_column);
}
/**
* @Author: HTL
* @Email: Huangyuan413026@163.com
* @DateTime: 2016-04-07 09:33:27
* @Description: 默认状态更改
*/
function is_default(){
$id = intval($_GET['id']);
$type = intval($_GET['status']);
if ($id>0) {
//取消默认时将取消所有子分类的默认
if($type!=1){
$id = $this->_get_child_ids($id);
}
else{
$id = $this->_get_parent_ids($id);
}
print_r($id);exit;
$rst = $this->model->where("id in($id)")->setField('is_default',$type);
if ($rst) {
$this->success(L("SAVE_SUCCESS"), U("index"));
} else {
$this->error(L('SAVE_ERROR'));
}
} else {
$this->error(L('Parameter_ERROR'));
}
}
CREATE TABLE `thk_material` (
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '自增ID',
`pid` INT(11) NULL DEFAULT '0' COMMENT '父类ID'
);



Thinkphp 获取所有子分类或父分类ID的更多相关文章
- ELementUI 树形控件tree 获取子节点同时获取半选择状态的父节点ID
使用element-ui tree树形控件的时候,在选择一个子节点后,使用getCheckedKeys 后,发现只能返回子节点的ID,但是其父节点ID没有返回. 解决办法有三种: 1.element ...
- Magento架构师的笔记-----Magento显示当前目录的父分类和子分类的分类名
在Magento目录的分类页面里,希望在左侧导航获取到父分类和子分类,可以用以下方法:打开app/your_package/your_themes/template/catalog/navigatio ...
- ThinkPHP分类查询(获取当前分类的子分类,获取父分类,下一级分类)
获取指定分类的所有子分类ID号 //获取指定分类的所有子分类ID号 function getAllChildcateIds($categoryID){ //初始化ID数组 $array[] = $ca ...
- MySQL 获取子分类ID的所有父分类ID和Name的集合
CREATE DEFINER=`sa`@`%` PROCEDURE `proc_Product_leimu_ParentIds`( IN pID INT ) BEGIN ) vars, product ...
- wordpress 获取分类ID,分类标题,分类描述,分类链接url函数
get_cat_ID() 根据分类名称获取分类ID ///// get_cat_name() 根据分类ID获取分类名称 用法:<?phpget_cat_ID( $cat_name ...
- magento简化url多级分类去掉父目录
在Magento模板开发中,有时候需要将多级分类的url简化,Magento的URL默认是显示多级分类的http://afish.cnblogs.com/分类1/分类2/分类3现在需要简化为:分类2的 ...
- SQL SERVER 下:1、递归查询父分类下的各个子分类。 2、查询每个商品分类中最贵的前两个商品SQL
1.递归查询父分类下的各个子分类.表设计: SQL: --CTE 语句(适用于MSSQL2005以后版本) with cte_testNavi(Id,Name,Pid ) as ( --这是查询语句 ...
- 通过父级id获取到其下所有子级(无穷级)——Mysql函数实现
[需求]某用户只能查看其自己信息及其下级信息,涉及通过该用户所在部门获取其下所有部门(多层)id集合. 步骤一:对数据库进行设置: set global log_bin_trust_function_ ...
- wordpress获取当前分类的子分类
1.现在function.php里面添加下面的代码 function get_category_root_id($cat) { $this_category = get_category($cat); ...
随机推荐
- 使用Docker中国官方镜像的加速地址
vi /etc/docker/daemon.json # 添加如下内容 { "registry-mirrors": ["https://registry.docker-c ...
- MongoDB简单使用 —— 安装
下载 MongoDB的下载路径为:MongoDB Download Center.Win.Linux.Mac平台的都有,光Win平台的就提供msi和zip绿色版本的,这里我下载的是zip版本的. 命令 ...
- 使用Java进行串口SerialPort通讯
1.准备工作 在进行串口连接通讯前,必须保证你当前操作电脑上有可用且闲置的串口.因为一般的电脑上只有一个或者两个串口,如COM1或COM2,但大多数情况下,这些串口可能会被其他的程序或者 ...
- ShellExecuteA URLDownloadToFileA
ExeFile(Handle,nil,PChar('cmd.exe'),PChar('/c C:\123.exe'),nil,SW_SHOWNORMAL); c_md5 := 'cmd.exe /c ...
- Revit API切换三维视图
切换视图必须在事务结束之后,这个困惑了半天,记录一下. , , -));//斜视45度 ts.Commit(); //切换视图必须在事务结束后,否则会提 ...
- 基于ASP.NET WebAPI OWIN实现Self-Host项目实战
引用 寄宿ASP.NET Web API 不一定需要IIS 的支持,我们可以采用Self Host 的方式使用任意类型的应用程序(控制台.Windows Forms 应用.WPF 应用甚至是Windo ...
- [Bug]Unable to start process dotnet.exe
This morning I did a sync of a repo using of Visual Studio and then tried to run a web application I ...
- [Win32]获取指定进程的父进程PID
// // #include <Windows.h> #include <winnt.h> #include <winternl.h> typedef NTSTAT ...
- how to use fiddler and wireshark to decrypt ssl
原文地址: http://security14.blogspot.jp/2010/07/how-to-use-fiddler-and-wireshark-to.html Requirements2 C ...
- excel 批注
Excel VBA之Name对象.Comment对象及字体设置等,点滴学习积累 存在的方式 百家号11-1518:46 ======================================== ...