/**
* 定义验证规则
* 格式:'字段名' => ['规则1','规则2'...]
*
* @var array
*/
protected $rule = [
'duration_time' => ['number', 'require'],
'timeout' => ['number', 'require'],
'start_location' => ['number', 'require'],
'show_interval' => ['number', 'require'],
];
/**
* 定义错误信息
* 格式:'字段名.规则名' => '错误信息'
*
* @var array
*/
protected $message = [
'duration_time.number' => ['code' => 4027, 'msg' => '4027'],
'timeout.number' => ['code' => 4027, 'msg' => '4027'],
'start_location.number' => ['code' => 4027, 'msg' => '4027'],
'show_interval.number' => ['code' => 4027, 'msg' => '4027'],
'duration_time.require' => ['code' => 4027, 'msg' => '4027'],
'timeout.require' => ['code' => 4027, 'msg' => '4027'],
'start_location.require' => ['code' => 4027, 'msg' => '4027'],
'show_interval.require' => ['code' => 4027, 'msg' => '4027'],
];
// 方法指定验证场景
protected $scene = [
'add' => ['duration_time', 'timeout', 'start_location', 'show_interval'],
'edit' => ['duration_time', 'timeout', 'start_location', 'show_interval'],
];
//对数据校验
try {
validate(\app\admin\validate\Advert::class)
->scene('edit')
->failException()
->check($request);
} catch (ValidateException $e) {
self::$code = $e->getError()['code'] ?? 0;
return false;
}
thinkphp6 验证器使用防止取回语言包结果
最新推荐文章于 2024-01-21 08:00:00 发布