//修改 public function actionUpdateNews(){ //接收前端json数据 $data = file_get_contents('php://input'); //解析json转成数组 $last_data = json_decode($data,true); //取值 $id = $last_data['id']; unset($last_data['id']); $model = News::findOne($id); foreach ($last_data as $k => $v){ $model->$k = $v; $model->save(false); } return ['code'=>200,'msg'=>'成功','data'=>null]; }