Yii2 ActiveForm 验证规则消息
Yii2 ActiveForm validation rules message
我在模型中有一些规则:
[['username', 'email', 'password', 'password_repeat'],'required', 'message' => 'Can not be blank'],
['username', 'string', 'min' => 2, 'max' => 255],
['password', 'string', 'min' => 6, 'max' => 255],
我设置了检查这些字段是否为空的消息。但是如何设置消息以检查输入长度。
我试过:
['username', 'string', 'min' => 2, 'max' => 255, 'message' => 'too few characters']
不过好像不太对。
您需要设置 tooShort
属性, http://www.yiiframework.com/doc-2.0/yii-validators-stringvalidator.html#$tooShort-detail
['username', 'string', 'min' => 2, 'max' => 255, 'tooShort' => 'too few characters']
我在模型中有一些规则:
[['username', 'email', 'password', 'password_repeat'],'required', 'message' => 'Can not be blank'],
['username', 'string', 'min' => 2, 'max' => 255],
['password', 'string', 'min' => 6, 'max' => 255],
我设置了检查这些字段是否为空的消息。但是如何设置消息以检查输入长度。
我试过:
['username', 'string', 'min' => 2, 'max' => 255, 'message' => 'too few characters']
不过好像不太对。
您需要设置 tooShort
属性, http://www.yiiframework.com/doc-2.0/yii-validators-stringvalidator.html#$tooShort-detail
['username', 'string', 'min' => 2, 'max' => 255, 'tooShort' => 'too few characters']