网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 php获取分门别类下面的所有子类方法
内容
    php获取分类下面的所有子类方法
    获取分类下面的所有子类方法:
    static function getMenuTree($arrCat, $parent_id = 0, $level = 0,$all=True)
    {
    static $arrTree; //使用static代替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]); //注销当前节点数据,减少已无用的遍历
    self::getMenuTree($arrCat, $value[ 'cid'], $level);
    }
    }
    return $arrTree;
    }
    用上面这个方法的前提是要把分类写到缓存文件中,缓存文件写入方法如下:
    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);
    }
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/28 12:20:36