多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
>[danger] 传入验证器规则数组进行验证 ``` $rules = [ 'username' => 'require', 'password' => 'require', ]; try { validate($rules)->check($data); } catch (\think\exception\ValidateException $e) { dump('验证失败: ' . $e->getError()); } ``` >[danger] 错误信息 ``` $rules = [ 'username' => 'require', 'password' => 'require', ]; $messages = [ 'username.require' => '用户名不能为空', ]; try { validate($rules, $messages)->check($data); } catch (\think\exception\ValidateException $e) { dump('验证失败: ' . $e->getError()); } ``` >[danger] 批量验证 + 第三个参数传入 true 代表进行批量验证 返回数组 ``` try { validate($rules, $messages, true)->check($data); } catch (\think\exception\ValidateException $e) { dump('错误信息数组: ', $e->getError()); } ``` >[danger] 是否抛出异常 + 第四个参数为false时,即使验证失败也不抛出异常 ``` try { validate($rules, $messages, true, false)->check($data); } catch (\think\exception\ValidateException $e) { dump('错误信息数组: ', $e->getError()); } ``` >[danger] 验证场景 此方式不需要验证场景,也没有意义,传入什么验证规则就验证什么