Php obtains all subclass methods under different categories. Php obtains all subclass methods under a category to obtain all subclass methods under a category: staticfunctiongetMenuTree ($ arrCat, $ parent_id0, $ level0, $ allTrue) {static $ arrTree; php retrieves all subclass methods under a category
Obtain all sub-classes of a category:
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]); // deregister the data of the current node to reduce useless traversal
Self: getMenuTree ($ arrCat, $ value ['CID'], $ level );
}
}
Return $ arrTree;
}
The premise of using this method is to write the classification to the cache file. the write method of the cache file 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 );
}
Methods used to obtain all sub-classes of a Category: static function getMenuTree ($ arrCat, $ parent_id = 0, $ level = 0, $ all = True) {static $ arrTree ;...