Skip to content

Commit

Permalink
修复array_multisort变量错误
Browse files Browse the repository at this point in the history
  • Loading branch information
itzcy committed Sep 22, 2020
1 parent ff52838 commit 7fe21d0
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 9 deletions.
2 changes: 2 additions & 0 deletions manage/app/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function save()
{
$stat = $this->db->insert('category', [
"pid" => $this->param['pid'],
"sort" => $this->param['sort'],
"category_name" => $this->param['category_name'],
]);
if ($stat) {
Expand All @@ -53,6 +54,7 @@ public function update()
'category',
[
"category_name" => $this->param['category_name'],
"sort" => $this->param['sort'],
"pid" => $this->param['pid'],
],
[
Expand Down
7 changes: 5 additions & 2 deletions manage/app/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public function __construct()
public function flush()
{

$menu = $this->db->select('category', '*');
$menu = $this->db->select('category', '*', [
"ORDER" => ["sort" => "ASC"]
]);
$menuTree = $this->toTree($menu);
$navigation = $this->db->select('nav', '*');
$navigation = $this->toClass($navigation, $this->toKVMenu($menu));
Expand Down Expand Up @@ -101,8 +103,9 @@ private function toClass($nav, $kvMenu)
private function sortNav($nav)
{
foreach ($nav as $key => $value) {
array_multisort(array_column($value, 'nav_sort'), SORT_DESC, $nav[$key]['nav']);
array_multisort(array_column($value['nav'], 'nav_sort'), SORT_DESC, $nav[$key]['nav']);
}

array_multisort(array_column($nav, 'sort'), SORT_ASC, $nav);
return $nav;
}
Expand Down
1 change: 0 additions & 1 deletion manage/app/Nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public function index()
public function create()
{
$category = $this->categoryToTree($this->db->select('category', '*'));
$nav = $this->db->get('nav', '*', ['id' => $this->param['id']]);
$this->fetch('view/index/add', [
'category' => $category
]);
Expand Down
Binary file modified manage/database.db
Binary file not shown.
7 changes: 6 additions & 1 deletion manage/view/category/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@
</div>
<br>
<div class="row">
<div class="col-xs-12">
<div class="col-xs-6">
<select class="form-control" name="pid" required>
<option value="0">顶级分类</option>
<?php foreach ($category as $item) : ?>
<option value="<?php echo $item['id']; ?>">|-- <?php echo $item['category_name']; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-xs-6">
<div class="input-control">
<input name="sort" type="text" class="form-control" placeholder="排序" required value="999">
</div>
</div>
</div>

<br>
Expand Down
9 changes: 7 additions & 2 deletions manage/view/category/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
</div>
<br>
<div class="row">
<div class="col-xs-12">
<div class="col-xs-6">
<select class="form-control" name="pid" required>
<option value="">请选择分类</option>
<option value="0">顶级分类</option>
<?php foreach ($category as $item) : ?>
<option value="<?php echo $item['id']; ?>">|-- <?php echo $item['category_name']; ?></option>
<?php if (isset($item['sub_category'])) : ?>
Expand All @@ -44,6 +44,11 @@
<?php endforeach; ?>
</select>
</div>
<div class="col-xs-6">
<div class="input-control">
<input name="sort" type="text" class="form-control" placeholder="排序" required value="<?php echo $item['sort'] ?>">
</div>
</div>
</div>
<br>

Expand Down
4 changes: 4 additions & 0 deletions manage/view/category/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<th>分类名称</th>
<!-- 以下三列中间可滚动 -->
<th class="flex-col" data-width="100">父级ID</th>
<th class="flex-col" data-width="100">排序ID</th>
<!-- 以下列右侧固定 -->
<th>操作</th>
</tr>
Expand All @@ -40,6 +41,9 @@
<td><?php echo $nav['id'] ?></td>
<td><?php echo $nav['category_name'] ?></td>
<td><?php echo $nav['pid'] ?></td>
<td>
<span class="label label-info"><?php echo $nav['sort'] ?></span>
</td>
<td>
<a href="?control=category&action=edit&id=<?php echo $nav['id']; ?>" class="btn btn-sm btn-primary" type="button">编辑</a>
<button class="btn btn-sm btn-danger" onclick="delNav(<?php echo $nav['id']; ?>)" type="button">删除</button>
Expand Down
4 changes: 2 additions & 2 deletions manage/view/index/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
<!-- HTML 代码 -->
<form class="form" action="?control=nav&action=save" method="post">
<div class="row">
<div class="col-xs-12">
<div class="col-xs-6">
<div class="input-control">
<input name="nav_name" type="text" class="form-control" placeholder="分类名称" required>
</div>
</div>
<div class="col-xs-12">
<div class="col-xs-6">
<select class="form-control" name="category_id" required>
<option value="">请选择分类</option>
<?php foreach ($category as $item) : ?>
Expand Down
3 changes: 2 additions & 1 deletion manage/view/index/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
<td><?php echo $nav['nav_desc'] ?></td>
<td><?php echo $nav['nav_link'] ?></td>
<td><?php echo $nav['nav_target'] ?></td>
<td><?php echo $nav['nav_sort'] ?></td>
<td>
<span class="label label-info"><?php echo $nav['nav_sort'] ?></span></td>
<td>
<a href="?control=nav&action=edit&id=<?php echo $nav['id']; ?>" class="btn btn-sm btn-primary" type="button">编辑</a>
<button class="btn btn-sm btn-danger" onclick="delNav(<?php echo $nav['id']; ?>)" type="button">删除</button>
Expand Down

0 comments on commit 7fe21d0

Please sign in to comment.