Browse Source

bug fix: breadcrumbs support subcates more than 2 levels

master
filesite 5 months ago
parent
commit
2aff4ae41d
  1. 39
      themes/beauty/controller/ListController.php
  2. 2
      themes/beauty/views/site/index.php

39
themes/beauty/controller/ListController.php

@ -49,6 +49,13 @@ Class ListController extends Controller {
$subcate = $scanResults[$cateId]; $subcate = $scanResults[$cateId];
$breadcrumbs = $this->getBreadcrumbs($menus, $subcate); $breadcrumbs = $this->getBreadcrumbs($menus, $subcate);
/*
header('Content-type: text/html; charset=utf-8');
print_r($subcate);
print_r($breadcrumbs);
print_r($menus);exit;
*/
//获取当前目录下的readme //获取当前目录下的readme
$cateReadmeFile = $scanner->getDefaultReadme($cateId); $cateReadmeFile = $scanner->getDefaultReadme($cateId);
if (!empty($cateReadmeFile)) { if (!empty($cateReadmeFile)) {
@ -99,6 +106,24 @@ Class ListController extends Controller {
return $out; return $out;
} }
//根据pid在目录数组里找出对应的父目录数据
protected function getParentCateByPid($pid, $cates) {
$parent = array();
foreach ($cates as $index => $item) {
if ($item['id'] == $pid) {
$parent = $item;
break;
}else if (!empty($item['directories'])) {
$parent = $this->getParentCateByPid($pid, $item['directories']);
if (!empty($parent)) {break;}
}
}
return $parent;
}
//根据目录结构以及当前目录获取面包屑 //根据目录结构以及当前目录获取面包屑
protected function getBreadcrumbs($menus, $subcate) { protected function getBreadcrumbs($menus, $subcate) {
$breads = array(); $breads = array();
@ -109,13 +134,17 @@ Class ListController extends Controller {
'url' => $subcate['path'], 'url' => $subcate['path'],
]); ]);
$foundKey = array_search($subcate['pid'], $this->array_column($menus, 'id')); $pid = $subcate['pid'];
if ($foundKey !== false) { $parentCate = $this->getParentCateByPid($pid, $menus);
while (!empty($parentCate)) {
array_unshift($breads, [ array_unshift($breads, [
'id' => $menus[$foundKey]['id'], 'id' => $parentCate['id'],
'name' => $menus[$foundKey]['directory'], 'name' => $parentCate['directory'],
'url' => $menus[$foundKey]['path'], 'url' => $parentCate['path'],
]); ]);
$pid = $parentCate['pid'];
$parentCate = $this->getParentCateByPid($pid, $menus);
} }
return $breads; return $breads;

2
themes/beauty/views/site/index.php

@ -160,7 +160,7 @@ eof;
//分割目录和文件 //分割目录和文件
echo '</div>'; echo '</div>';
if (!empty($category['files'])) { if (!empty($category['files']) && count($category['files']) > 3) {
echo '<hr>'; echo '<hr>';
} }
echo '<div class="im_mainl row">'; echo '<div class="im_mainl row">';

Loading…
Cancel
Save