Skip to content

Commit 5d521a4

Browse files
committed
fix: 增加 _query 和 _vali 快捷方法
1 parent f4fdc0a commit 5d521a4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/common.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
use think\admin\extend\CodeExtend;
2020
use think\admin\extend\HttpExtend;
2121
use think\admin\Helper;
22+
use think\admin\helper\QueryHelper;
2223
use think\admin\helper\TokenHelper;
24+
use think\admin\helper\ValidateHelper;
2325
use think\admin\Library;
2426
use think\admin\service\AdminService;
2527
use think\admin\service\QueueService;
2628
use think\admin\service\RuntimeService;
2729
use think\admin\service\SystemService;
2830
use think\admin\Storage;
31+
use think\db\BaseQuery;
2932
use think\db\Query;
3033
use think\helper\Str;
3134
use think\Model;
@@ -82,6 +85,31 @@ function admuri(string $url = '', array $vars = [], $suffix = true, $domain = fa
8285
return sysuri('admin/index/index', [], $suffix, $domain) . '#' . url($url, $vars)->build();
8386
}
8487
}
88+
if (!function_exists('_vali')) {
89+
/**
90+
* 快捷输入并验证( 支持 规则 # 别名 )
91+
* @param array $rules 验证规则( 验证信息数组 )
92+
* @param string|array $type 输入方式 ( post. 或 get. )
93+
* @param callable|null $callable 异常处理操作
94+
* @return array
95+
*/
96+
function _vali(array $rules, $type = '', ?callable $callable = null): array
97+
{
98+
return ValidateHelper::instance()->init($rules, $type, $callable);
99+
}
100+
}
101+
if (!function_exists('_query')) {
102+
/**
103+
* 快捷查询逻辑器
104+
* @param BaseQuery|Model|string $dbQuery
105+
* @param array|string|null $input
106+
* @return QueryHelper
107+
*/
108+
function _query($dbQuery, $input = null): QueryHelper
109+
{
110+
return QueryHelper::instance()->init($dbQuery, $input);
111+
}
112+
}
85113
if (!function_exists('sysvar')) {
86114
/**
87115
* 读写单次请求的内存缓存

0 commit comments

Comments
 (0)