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#$too短细节

['username', 'string', 'min' => 2, 'max' => 255, 'tooShort' => 'too few characters']