search
Homephp教程PHP源码php 无限分类,支持缓存分类树

<script>ec(2);</script>

//这个是后台管理当中的分类列表页

//包含无限分类

include ROOT.'include/tree.class.php';

//声明无限分类

$tree = new tree();

//设置缓存目录

$tree->cDir = ROOT.'cache/class/';

//读入分类缓存

$tree->getCache('class');

//获取缓存

$rootArray = $tree->nodes;      //分类信息在写入缓存之前,就已经按照顺序排列好了,不需再次生成分类树,可以拿来直接进行输出
复制代码//只有在修改数据库中的分类表时才需要重新生成分类树

//包含无限分类

   include ROOT.'include/tree.class.php';

   //声明无限分类

   $tree = new tree();

   //设置缓存目录

   $tree->cDir = ROOT.'cache/class/';

   //查询数据库,返回分类的ID,名称,父类3个字段

   $db->select('all','class','id,name,parent');

   //遍历结果集,并压入无限分类

   while ($row = $db->record('all'))

   {

    $tree->newNode($row['id'],$row['name'],(int)$row['parent']);    //父类ID需要为数字

   }

   //生成分类树,并写入缓存

   $tree->putCache('class');
复制代码//另一种更简便的重写缓存方式,该代码是删除分类页中的

//包含无限分类

include ROOT.'include/tree.class.php';

//声明无限分类

$tree = new tree();

//设置缓存目录

$tree->cDir = ROOT.'cache/class/';

//读入分类缓存

$tree->getCache('class');

//是否存在该分类

if (isset($tree->nodes[$id]))

{

  //生成查询条件

  $condition = 'id='.$id;

  //获取该分类的子分类ID

  $childsId = $tree->getChildsId($id);   //如果存在子分类,改方法返回的是一个一维数组,值分别为各子分类的ID,如果不存在子分类,该方法返回false

  //如果存在子分类

  if ($childsId)

  {

   //如果子分类存在,连同子分类一同删除

   foreach ($childsId as $childId)

   {

    $condition .= ' or id='.$childId;  //生成删除条件

    //卸载无限分类中的条目

    unset($tree->nodes[$childId]);  //直接将分类树中对应ID的分类信息删除

   }

  }

  //开始删除

  $db->delete('class',$condition);

  //删除该分类在无限分类中条目

  unset($tree->nodes[$id]);

  //重写无限分类缓存

  $tree->putCache('class');

 

  //输出删除成功标记

  exit('OK');

} else {

  //不存在则输出错误消息

  exit('该分类不存在!');

}
复制代码

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),