This is the Category List page in the background management
Contains infinite categories
Include ROOT. ' include/tree.class.php ';
declaring infinite categories
$tree = new Tree ();
Set Cache Directory
$tree->cdir = ROOT. ' cache/class/';
Read into the category cache
$tree->getcache (' class ');
Get Cache
$rootArray = $tree->nodes; Classification information is sorted in order before it is written to the cache, and can be directly output without the need to generate a classification tree again
Copy code//You need to regenerate the taxonomy tree only if you are modifying a taxonomy table in the database
Contains infinite categories
Include ROOT. ' include/tree.class.php ';
declaring infinite categories
$tree = new Tree ();
Set Cache Directory
$tree->cdir = ROOT. ' cache/class/';
Query the database, return the category ID, name, parent Class 3 fields
$db->select (' All ', ' class ', ' id,name,parent ');
Traverse the result set and press into the infinite category
while ($row = $db->record (' All '))
{
$tree->newnode ($row [' id '], $row [' Name '], (int) $row [' parent ']); The parent class ID needs to be a number
}
Generate the taxonomy tree and write to the cache
$tree->putcache (' class ');
Copy code//Another simpler way to override caching, which is to delete the
Contains infinite categories
Include ROOT. ' include/tree.class.php ';
declaring infinite categories
$tree = new Tree ();
Set Cache Directory
$tree->cdir = ROOT. ' cache/class/';
Read into the category cache
$tree->getcache (' class ');
Whether the taxonomy exists
if (Isset ($tree->nodes[$id]))
{
Generate query criteria
$condition = ' id= '. $id;
Gets the subcategory ID of the taxonomy
$childsId = $tree->getchildsid ($id); If a subcategory exists, the modified method returns a one-dimensional array with values of the IDs for each subcategory, or False if no subcategories exist
If a subcategory exists
if ($childsId)
{
If the subcategory exists, it is deleted along with the sub category
foreach ($childsId as $childId)
{
$condition. = ' or id= '. $childId; To generate a delete condition
Unload an entry in an infinite category
unset ($tree->nodes[$childId]); Delete the category information of the corresponding ID in the classification tree directly
}
}
Start deletion
$db->delete (' class ', $condition);
Delete the category entry in the infinite category
unset ($tree->nodes[$id]);
overriding an infinite category cache
$tree->putcache (' class ');
Output Deletion Success token
Exit (' OK ');
} else {
Output error message if not present
Exit (' This category does not exist! ');
}
Copy Code