Home > Article > Backend Development > thinkphp method to get the current position of the column and article, _PHP tutorial
The example in this article describes how thinkphp obtains the current position of columns and articles. Share it with everyone for your reference. The specific implementation method is as follows:
Today I improved some details of the blog, including modifying the "current location" on the column page and article page. In the past, there were only a few columns, so we just used the blind method (Home Page -> Column Name), but now there are more columns, and gradually second-level columns and third-level columns are also coming. This method is obviously not suitable, so we improved it. one time. It's not difficult, just use a recursive function.
The test results are shown below:
View the source file effect:
protected function now_here($catid,$ext=''){
$cat = M("Category");
$here = 'Homepage';
$uplevels = $cat->field("catid,catname,asmenu")->where("catid=$catid")->find();
if($uplevels['asmenu'] != 0)
$here .= $this->get_up_levels($uplevels['asmenu']);
$here .= ' -> '.$uplevels['catname']."";
if($ext != '') $here .= ' -> '.$ext;
return $here;
}
protected function get_up_levels($id){
$cat = M("Category");
$here = '';
$uplevels = $cat->field("catid,catname,asmenu")->where("catid=$id")->find();
$here .= ' -> '.$uplevels['catname']."";
if($uplevels['asmenu'] != 0){
$here = $this->get_up_levels($uplevels['asmenu']).$here;
}
return $here;
}
I hope this article will be helpful to everyone’s PHP programming design.