时间:2021-07-01 10:21:17 帮助过:6人阅读
//通过id_category获取一级分类id
function getParentInfo(){
$id_category=Tools::getValue('id_category');
$cate_info=$this->category_obj->where('id_category='.$id_category)->find();
//不是顶级
if($cate_info['pid']!=0){
$result=$this->getFirst($id_category);
}else{
$result=$cate_info;
}
dump($result);
// dump('顶级类是:'.$result['id_category'].':'.$result['name'].'
');
}
function getFirst($id_category){
$cate_info=$this->category_obj->where('id_category='.$id_category)->find();
echo $this->category_obj->getLastSql().'
';
if($cate_info['pid']!=0){
$this->getFirst($cate_info['pid']);
}else{
dump($cate_info);
return $cate_info;
}
}
function getFirst($id_category){
$cate_info=$this->category_obj->where('id_category='.$id_category)->find();
echo $this->category_obj->getLastSql().'
';
if($cate_info['pid']!=0){
$cate_info =$this->getFirst($cate_info['pid']);
}
return $cate_info;
}
------解决方案--------------------
要有返回值!