Hi,
I am using Yii2 basic application. I am using REST API. I have a studentrecords table containing Id,FirstName,LastName,Class columns. Here Id is Primary key and auto_incremented.
I have set the application configuration as required for the REST API. Below is the Studentrecords Controller
<?php
namespace app\controllers;
use Yii;
use yii\rest\ActiveController;
use app\models\Studentrecords;
class StudentrecordsController extends ActiveController
{
public $modelClass = 'app\models\Studentrecords';
public function behaviors()
{
return [
[
'class' => \yii\filters\ContentNegotiator::className(),
'only' => ['index'],
'formats' => [
'application/json' => \yii\web\Response::FORMAT_JSON,
],
],
];
}
public function actionIndex()
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
}
}
I am using POSTMAN to test my API. Here GET request is working fine. But when I use POST and try to supply the values in Body, then the response I return is not proper, but the values are getting saved into tables. When I preview the tab on Postman, foll error is displayed.
# Invalid Argument – [yii\base\InvalidArgumentException](http://www.yiiframework.com/doc-2.0/yii-base-invalidargumentexception.html)
## Response content must not be an array.
What should I do?