在使用Thinkphp5.1进行项目开发的时候,报出了一个错误:Indirect modification of overloaded element....has no effect。
详细代码如下:
- /**
- * @title 需求大厅
- * @author zxn
- * @url /member/master/need_hall
- * @param name:fix_type type:integer require:0 default: desc:安装类型
- * @param name:status type:integer require:0 default: desc:派工状态
- * @method POST
- * @header name:Authorization require:1 default:1455523e6d407a3c desc:token
- */
- public function need_hall(){
- $param = $this->request->param();
- $map = [];
- $map[] = ['is_deleted','=',0];
- if(isset($param['fix_type']) && $param['fix_type'] >= 0) $map[] = ['fix_type','=',intval($param['fix_type'])];
- if(isset($param['status']) && in_array($param['status'],[0,1])) $map[] = ['status','=',intval($param['status'])];
- $list = MemberDemandModel::where($map)->with('member')
- ->order('id desc')
- ->field('master_id,master_name,master_mobile,master_time,is_deleted,mobile,address',true)
- ->paginate()
- ->each(function ($item){
- $images = explode(",",$item['images']);
- $image_list = [];
- foreach ($images as &$key){
- $image_list[] = set_up_img($key);
- }
- $item['images'] = $image_list;
- $item['fix_type'] = MasterModel::getFixTypeAttr($item['fix_type']);
- $item['member']['avatar'] = getAvatar($item['member']['avatar']);
- return $item;
- });
- return returnData(1,'请求成功',$list);
- }
上述代码是修改后的。原因是模型查询each()中不能使用foreach遍历对数据元素进行赋值,解决办法是采用一个中间变量,比如上述代码中的image_list