建立测试验证TestValidate.php
```
<?php
namespace app\api\validate;
use think\Validate;
class TestValidate extends Validate
{
protected $rule = [
'name' => 'require|max:10',
'email' => 'email'
];
}
```
在banner.php中测试
```
<?php
namespace app\api\controller\v1;
use think\Validate;
use app\api\validate\TestValidate;
class Banner{
//获取指定id的banner信息
public function getBanner($id)
{
//2.验证器
//验证数据
$data=[
'name'=>'vendor111111',
'email'=>'vendorqq.com'
];
//验证规则
$validate =new TestValidate();
//执行验证//加上batch为批量验证
$result=$validate->batch()->check($data);
var_dump($validate->getError());
}
}
```
结果
![](https://box.kancloud.cn/7aecea8976f5c850866cea9ba09537c7_825x534.png)