标签:batch 提示 res var_dump email err protect mail 输出
我才知道原来验证有两种类型,独立验证和验证器,当然我们工作中肯定用验证器喽,代码的封装性也好很多,其实我觉得代码的维护性也好很多;
独立验证:
//独立验证
$data = [
‘name‘ => ‘vendor125578‘,
‘email‘ => ‘vendor‘
];
//验证规则 ->内置规则
$validate = new Validate([
‘name‘ => ‘require|max:10‘,
‘email‘ => ‘email‘
]);
//执行 单独验证
$result = $validate->check($data);
echo $validate->getError();
//执行 批量验证 [batch]
$result = $validate->batch()->check($data);
//输出错误提示
var_dump($validate->getError());
验证器:
//验证器类
use think\Validate;
class TestValidata extends Validate
{
//验证规则
protected $rule=[
‘name‘ => ‘require|max:10‘,
‘email‘ => ‘email‘
];
}
要验证的数据:
$data = [
‘name‘ => ‘vendor125578‘,
‘email‘ => ‘vendor‘
];
//验证器对象;
$validate = new TestValidata();
//执行 批量验证
$result = $validate->batch()->check($data);
//输出错误提示
var_dump($validate->getError());
标签:batch 提示 res var_dump email err protect mail 输出
原文地址:http://www.cnblogs.com/fangyinghua/p/7400582.html