doupian9490 2017-01-12 10: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 10:50
    关注

    Last line should be

    [['name', 'city', 'post_code', 'street'], 'required']
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • douci1918 2017-01-12 11:34
    关注

    There is mistake in your last index please change it to

     [['name', 'city', 'post_code', 'street'],'required']
    
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Erasure Code纠删码表
  • ¥15 用vite创建的vue3项目,404重定向不起作用??
  • ¥15 关于#c语言#的问题:一个球从80米高度自由落下,每次落地后反弹的高度为原高度的一半计算6次小球反弹的高度.(反弹结果取整,使用走走for循环结构)
  • ¥15 SurfaceControl的screenshot问题
  • ¥15 基于51单片机的oled菜单代码,要C语言,模块化编程!
  • ¥15 JAVAswing,设计一个扑克牌什么的
  • ¥50 python ctypes调用dll实现分析
  • ¥40 用python解决数据统计问题
  • ¥100 是否有方案能通过抓包分析得到移动应用的名称和包名信息?
  • ¥15 opencv检测不到轮廓