THINKCMF获取面包屑导航数据方法

      发布在:后端技术      评论:0 条评论
/**
* 获取面包屑数据
* @param int     $categoryId  当前文章所在分类,或者当前分类的id
* @param boolean $withCurrent 是否获取当前分类
* @return array 面包屑数据
*/
public static function breadcrumb($categoryId, $withCurrent = false)
{
$data = [];
$portalCategoryModel = new PortalCategoryModel();

$path = $portalCategoryModel->where(['id' => $categoryId])->value('path');

if (!empty($path)) {
$parents = explode('-', $path);
if (!$withCurrent) {
array_pop($parents);
}

if (!empty($parents)) {
$data = $portalCategoryModel->where('id', 'in', $parents)->order('path ASC')->select();
}
}

return $data;
}

由于在实际使用中使用了其他表来保存数据我们就可以使用这个方法来改造了

相关文章
热门推荐