【问题标题】:Yii2 ActiveForm validation rules messageYii2 ActiveForm 验证规则消息
【发布时间】:2016-04-11 15:18:08
【问题描述】:

我在模型中有一些规则:

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

【问题讨论】:

    标签: php yii2 active-form


    【解决方案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']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多