位置:  首页 -> 编程语言 -> PHP -> TP5 -> TP5实现面包屑

TP5实现面包屑


//**
     * [面包屑]
     * @param  [int] $id [文章id]
     * @param  [int] $cid  [文章栏目id]
     * @param  [string] $ext [文章标题]
     * @return [string] $here; [完整面包屑]
     */
  protected function now_here($id,$cid,$ext=''){

   $here = ' 首页';

   $uplevels = $this->db->table('article_cates')->field("id,cate_name,pid")->where("id=$cid")->item();

   if($uplevels['pid'] != 0){

   $here .= $this->get_up_levels($uplevels['pid']);
   }
   $here .= ' -> '.$uplevels['cate_name']."";

   if($ext != '') $here .= ' -> '.$ext;

   return $here;

}
/**
     * [递归获取栏目名称]
     * @param  [int] $id [文章父id]
     * @return [string] $here; [父栏目名称]
     */
protected function get_up_levels($id){

   $here = '';

   $uplevels = $this->db->table('article_cates')->field("id,cate_name,pid")->where("id=$id")->item();

   $here .= ' -> '.$uplevels['cate_name']."";

   if($uplevels['pid'] != 0){

      $here = $this->get_up_levels($uplevels['pid']).$here;

   }

   return $here;

}

到底了 6

相关阅读