简体   繁体   English

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

[英]Yii2 - model rules 'required' fails

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? 是什么原因引起的?

最后一行应该是

[['name', 'city', 'post_code', 'street'], 'required']

您的上一个索引有误,请将其更改为

 [['name', 'city', 'post_code', 'street'],'required']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM