yii2学习笔记,错误总结,持续更新

yii2学习笔记,错误总结,持续更新

标签: yii
2016-02-12 10:54 140人阅读 评论(0) 收藏 举报
分类:

版权声明:本文为博主原创文章,未经博主允许不得转载。

服务器500错误

  • 数据库访问出现错误,查看sql语句是不是出现问题

Either ‘name’, or ‘model’ and ‘attribute’ properties must be specified

  • 当我进行数据库的查询的时候,如果返回的内容过多,通常会使用asArray将返回的 模型进行数组化,从而减少占用内存空间, 但是如果我们要将返回的数据传递给 视图的时候,就不能数组化了,否则,就会出现这种错误

ajax请求取不到返回数据

  • ajax是封装到 get\post请求里的, 当我们在要进行if语句判断是ajax、post、get请求的时候,要将ajax请求放在最前。

数据更新

  • 当使用表单提交的数据进行更新数据库中的数据的时候
  • 对于表单提交的数据,不能用yii\db\ActiveRecord::load()或yii\db \ActiveRechord::attributes 进行赋值,会报错,不知为什么。 只能使用yii\db\ActiveRecord::属性名 = value,进行赋值,如下:
    `
    session=\Yii::app->session;
    res1=Workexperience::find()>where([uerid=>session[‘user_id’]])->orderBy(‘date_begin’)->all();
    sourcecount=Workexperience::find()>where([uerid=>session[‘user_id’]])->orderBy(‘date_begin’)->count();
    if(\Yii::app>request>isAjax)return$sourcecount;elseif(\Yii::app->request->isPost){
    res2=\Yii::app->request->post(‘Work_experience’);

        foreach($res_2 as $index => $value){         if($index < $source_count){             $res_1[$index]->date_begin = $value['date_begin'];             $res_1[$index]->date_end = $value['date_end'];             $res_1[$index]->company=$value['company'];             $res_1[$index]->department=$value['department'];             $res_1[$index]->position=$value['position'];             $res_1[$index]->scenario='submit';          }         else {             $res_1[$index] = new Work_experience(['scenario'=>'submit']);             $res_1[$index]->attributes = $value;             $res_1[$index]->uer_id = $session['user_id'];         }         if($res_1[$index]->validate()){             $res_1[$index]->save();          }     }` 
0
0
posted @   编程未来  阅读(185)  评论(0编辑  收藏  举报
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示