Hi,
I am using REST API in yii2. I have a table called studentrecords. The controller is foll
<?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','create','update','delete'],
'formats' => [
'application/json' => \yii\web\Response::FORMAT_JSON,
],
],
];
}
public function actionIndex()
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
}
public function actions()
{
$actions = parent::actions();
// disable the "delete" and "create" actions
unset($actions['create']);
return $actions;
}
public function prepareDataProvider()
{
// prepare and return a data provider for the "index" action
}
public function actionCreate()
{
$model = new Studentrecords();
$model->load(Yii::$app->request->post());
$model->save(false);
return $model;
}
}
Here when I use Postman for POST request to the API http://localhost/student/web/studentrecords then the output is
{
"Id": 30
}
Only the Id is getting saved in table. Other fields are not getting saved. What to do?