doupian9490 2017-01-12 02:49
浏览 61
已采纳

Yii2 - 模型规则“必需”失败

I have simple form, which collects: name, city, street and post_code. These are rules that I have:

return [
    [['city', 'street', 'name'], 'string', 'max' => 255],
    [['post_code'], 'string', 'max' => 6],
    ['post_code', 'match', 'pattern' => '/^([0-9]{2})(-[0-9]{3})?$/i'],
    [['name', 'city', 'post_code', 'street'] => 'required']
];

It returns me error "Illegal offset type" and marks first line to be faulty, but when I comment the last line, it works fine (but of course doesn't require values to be written). What can it be caused by?

  • 写回答

2条回答 默认 最新

  • dongxianshuai8927 2017-01-12 02:50
    关注

    Last line should be

    [['name', 'city', 'post_code', 'street'], 'required']
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部