邮递员在YII2中开发的邮寄请求抛出“意外的'<'”错误

时间:2019-05-03 11:40:10

标签: yii2

过去两天我都收到了此消息,但还无法修复。任何指针将不胜感激:

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];  
} 

1 个答案:

答案 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];  
}