2014-12-22 17:42:12 4196次浏览 1条回答 2 悬赏 5 金钱

比如定义好几个字段都不允许为空,错误提示为:字段名+错误提示,怎么写message语句;就是保证错误信息自动调用当前的attributeLabes的标签!
类似以下写法

public function rules()
{
    return [
        [['title', 'image', 'content'], 'required','message'=>"{{$attribute}}不能为空"],
        [['content'], 'string'],
        [['title', 'image'], 'string', 'max' => 225]
    ];
}
补充于 2014-12-22 20:16
{
    return [
        [['title', 'image', 'content'], 'required','message'=>"{attribute}不能为空"],
        [['content'], 'string'],
        [['title', 'image'], 'string', 'max' => 225]
    ];
}

最佳答案

  • Ricky_nie 发布于 2014-12-25 13:26 举报
    public function rules()
    {
        return [
            [['title', 'image', 'content'], 'required','message'=>"{attribute}不能为空"],
            [['email'], 'unique','message'=>'{attribute}"{value}"已经被占用了'],
            [['title', 'image'], 'string', 'max' => 225]
        ];
    }
    

    其中{attribute}是属性名称,{value}是用户输入的值

    没有找到数据。
您需要登录后才可以回答。登录 | 立即注册
zfeig
主管

zfeig

注册时间:2014-07-29
最后登录:2015-09-29
在线时长:36小时6分
  • 粉丝55
  • 金钱75
  • 威望30
  • 积分735

热门问题