Skip to content

Commit

Permalink
改进Mongo的order方法
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Jan 15, 2025
1 parent fd483bb commit 8e28d92
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/db/Mongo.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,9 @@ public function limit(int $offset, ?int $length = null)
public function order($field, string $order = '')
{
if (is_array($field)) {
$this->options['sort'] = $field;
$this->options['sort'] = array_map(function ($val) {
return 'asc' == strtolower($val) ? 1 : -1;
}, $field);
} else {
$this->options['sort'][$field] = 'asc' == strtolower($order) ? 1 : -1;
}
Expand Down Expand Up @@ -564,9 +566,9 @@ public function paginate($listRows = null, $simple = false): Paginator
}

$defaultConfig = [
'query' => [], //url额外参数
'fragment' => '', //url锚点
'var_page' => 'page', //分页变量
'query' => [], //url额外参数
'fragment' => '', //url锚点
'var_page' => 'page', //分页变量
'list_rows' => 15, //每页数量
];

Expand Down

0 comments on commit 8e28d92

Please sign in to comment.