Yii2 ActiveForm验证规则消息

时间:2016-04-11 15:18:09

标签: php yii2 active-form

我在模型中有一些规则:

[['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'] 但它似乎并不正确。

1 个答案:

答案 0 :(得分:1)

您需要设置tooShort属性,http://www.yiiframework.com/doc-2.0/yii-validators-stringvalidator.html# $ tooShort-detail

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