过去两天我都收到了此消息,但还无法修复。任何指针将不胜感激:
public function actionInsert()
{
\Yii:: $app->response->format = \yii\web\Response:: FORMAT_JSON;
$postData = Yii::$app->request->post();
$connection = \Yii::$app->db;
$connection->createCommand()->insert('user', [
'username' => $postData['$username'],
'status' => $postData['$status'],
])
->execute();
return ['status' => true, 'data' => $postData];
}
答案 0 :(得分:0)
您应该选择表格上没有$符号的字段名称。试试这个
public function actionInsert()
{
\Yii:: $app->response->format = \yii\web\Response:: FORMAT_JSON;
$postData = Yii::$app->request->post();
$connection = \Yii::$app->db;
$connection->createCommand()->insert('user', [
'username' => $postData['username'],
'status' => $postData['status'],
])
->execute();
return ['status' => true, 'data' => $postData];
}