Home > Backend Development > PHP Tutorial > tp框架写了个步骤获取顶级分类return结果就是null,在辅助函数都能打印出结果

tp框架写了个步骤获取顶级分类return结果就是null,在辅助函数都能打印出结果

WBOY
Release: 2016-06-13 13:09:27
Original
905 people have browsed it

tp框架写了个方法获取顶级分类return结果就是null,在辅助函数都能打印出结果。

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->     //通过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'].'<br>');
     }    
    function getFirst($id_category){     
          $cate_info=$this->category_obj->where('id_category='.$id_category)->find();   
          echo $this->category_obj->getLastSql().'<br>';  
          if($cate_info['pid']!=0){
               $this->getFirst($cate_info['pid']);               
          }else{
               dump($cate_info);
               return $cate_info;
          }          
     }

Copy after login

我拿分类id=115测试结果是在下面getFirst能打印出结果也是想要的结果,但是:return $cate_info给$result时候就是NULL了
求高手指点!!!

------解决方案--------------------
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;
}
}

------解决方案--------------------
PHP code


function getFirst($id_category){   
  $cate_info=$this->category_obj->where('id_category='.$id_category)->find();   
       echo $this->category_obj->getLastSql().'<br>';   
  if($cate_info['pid']!=0){
       $cate_info =$this->getFirst($cate_info['pid']);   
  }
      return $cate_info;
    }
<br><font color="#e78608">------解决方案--------------------</font><br>要有返回值! <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template