duanqianruan8448 2016-04-11 15:18
浏览 60
已采纳

Yii2 ActiveForm验证规则消息

I have some rules in the model:

[['username', 'email', 'password', 'password_repeat'],'required', 'message' => 'Can not be blank'],
['username', 'string', 'min' => 2, 'max' => 255],
['password', 'string', 'min' => 6, 'max' => 255],

I set the message for checking if any of these fields were blank. But how can I set messages to check inputs length.

I've tried:

['username', 'string', 'min' => 2, 'max' => 255, 'message' => 'too few characters'] Yet it doesn't seem to be correct.

  • 写回答

1条回答 默认 最新

  • dongyan1841 2016-04-11 15:37
    关注

    You need to set the tooShort property, http://www.yiiframework.com/doc-2.0/yii-validators-stringvalidator.html#$tooShort-detail

    ['username', 'string', 'min' => 2, 'max' => 255, 'tooShort' => 'too few characters']
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?