PHP gets all the subclass methods below the category
Get all the subclass methods below the taxonomy:
static function Getmenutree ($arrCat, $parent _id = 0, $level = 0, $all =true)
{
Static $arrTree; Use static instead of global
if (! $all) $arrTree = ';
if (empty ($arrCat)) return FALSE;
$level + +;
if ($level = = 1) $arrTree [] = $parent _id;
foreach ($arrCat as $key => $value)
{
if ($value [' parent_cid '] = = $parent _id)
{
$value [' level '] = $level;
$arrTree [] = $value [' CID '];
Unset ($arrCat [$key]); Log off the current node data to reduce the already useless traversal
Self::getmenutree ($arrCat, $value [' CID '], $level);
}
}
return $arrTree;
}
The premise of the above method is to write the classification to the cached file, and the cached file write method is as follows:
Public Function ActionIndex2 ()
{
$filepath = Yii::getpathofalias (' application '). ' /data/';
$arr = Array ();
$db = Yii::app ()->db;
$listinfo = $db->createcommand ("Select Name,cid,parent_cid,root_cid from Item_cat_info")->queryall ();
foreach ($listinfo as $val)
{
$arr [$val [' cid ']] = Array (' CID ' => $val [' CID '], ' name ' => $val [' name '], ' parent_cid ' => $val [' parent_cid '], ' Root_cid ' => $val [' root_cid ']);
}
$applist = " ";
File_put_contents ($filepath. ' itemcat.php ', $applist);
}