php如何通过无限极分类创建文件夹并纯静态分类下的内容

来源:互联网 发布:淘宝模拟试衣间在哪了 编辑:程序博客网 时间:2024/06/07 00:14
/**这是主题内容*/$type = DB::table('classify')->getAll();    //获取所有的分类$type = $this->get_tree($type);              //获取无限极分类的数组形式//根据分类级别创建文件夹$result = $this->type_mkdir($type);
//判断文件夹是否创建成功if($result){    //获取所有文章    $list = DB::table('article')->join('classify','join','article.cid=classify.cid')->getAll();       //print_r($list);die;    //生成静态文件    foreach($list as $k=>$v){        //开启ob缓存        ob_start();        $this->assign('list',$v);        $this->render('article/art_show_one');        //获取缓冲区的内容        $str = ob_get_contents();        //根据文章类型定义路径        $path = iconv('utf-8', 'gbk','./tmp'.$this->get_static_path($v['pid']).'/'.$v['c_name'].'/'.$v['art_title'].'.html');  //转移成中文的类型        //生成html静态页面        file_put_contents($path, $str) ;        //清除缓冲区        ob_end_clean();    }    alert('友情提示', '更新静态文件成功!', 'Article/arts_show');}else{    alert('错误提示', '更新静态文件失败', 'Article/arts_show');}


/*
*无限极分类
*/
public function get_tree($data,$pid=0){    $arr=array();    foreach($data as $key=>$v)    {        if($v['pid']==$pid)        {            $arr[$key]=$v;            $arr[$key]['son']= $this->get_tree($data,$v['cid']);  //region_id  是它的id        }    }    return $arr;}

/*
*通过无限极分类的数组类型 创建文件夹
*/
public function type_mkdir($type,$t_name=''){    static $error=true;    foreach($type as $k=>$v) {        $path = iconv('utf-8', 'gbk','./tmp/'.$t_name.$v['c_name']);        if(!is_dir($path)){            if(!mkdir($path)){                $error = false;            }            if(!empty($v['son'])){                $this->type_mkdir($v['son'],$t_name.$v['c_name'].'/');            }        }    }    return $error;}

/*
*获取路径
*/
public function type_mkdir($type,$t_name=''){    static $error=true;    foreach($type as $k=>$v) {        $path = iconv('utf-8', 'gbk','./tmp/'.$t_name.$v['c_name']);        if(!is_dir($path)){            if(!mkdir($path)){                $error = false;            }            if(!empty($v['son'])){                $this->type_mkdir($v['son'],$t_name.$v['c_name'].'/');            }        }    }    return $error;}

0 0