setTypeMsg() public static method

获取验证规则的默认提示信息
public static setTypeMsg ( string | array $type, string $msg = null ) : void
$type string | array 验证规则类型名称或者数组
$msg string 验证提示信息
return void
Exemplo n.º 1
0
 public function testSetTypeMsg()
 {
     $rule = ['name|名称' => 'require|max:25', 'age' => 'number|between:1,120', 'email' => 'email', ['sex', 'in:1,2', '性别错误']];
     $data = ['name' => '', 'age' => 10, 'email' => '*****@*****.**', 'sex' => '3'];
     $validate = new Validate($rule);
     $validate->setTypeMsg('require', ':attribute必须');
     $validate->setTypeMsg(['require' => ':attribute必须']);
     $result = $validate->batch()->check($data);
     $this->assertFalse($result);
     $this->assertEquals(['name' => '名称必须', 'sex' => '性别错误'], $validate->getError());
 }