The Yii Framework framework gets all the subclass methods below the classification

  • 2021-07-01 07:02:03
  • OfStack

Gets all the subclass methods below the classification:


static function getMenuTree($arrCat, $parent_id = 0, $level = 0,$all=True)
 {
  static $arrTree; // Use static Substitute 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 useless traversal 
    self::getMenuTree($arrCat, $value[ 'cid'], $level);
   }
  }
  return $arrTree;
 }

The premise of using the above method is to write the classification to the cache file. The cache file writing 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 = "<?php\nreturn ".var_export($arr, true).";\n?>";
 file_put_contents($filepath.'itemcat.php', $applist);
  }


Related articles: