I am new to php development. Just for practicing I am creating a rest API following a video tutorial. I have followed each and every step but still unable to get the desired result. Below is the code
Employee Model
class Employee extends \yii\db\ActiveRecord { const SCENARIO_CREATE = 'create'; /** * @inheritdoc */ public static function tableName() { return 'employee'; } /** * @inheritdoc */ public function rules() { return [ [['emp_name', 'emp_email', 'emp_sal'], 'required'], [['emp_name', 'emp_email', 'emp_sal'], 'string', 'max' => 100], ]; } public function scenarios() { $scenarios = parent::scenarios(); $scenarios['create'] = ['emp_name','emp_email', 'emp_sal']; return $scenarios; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'emp_name' => 'Emp Name', 'emp_email' => 'Emp Email', 'emp_sal' => 'Emp Sal', ]; } } Above the ID field is auto-increment
Employee Controller
public function actionCreateEmployee() { \Yii::$app->response->format= \yii\web\Response::FORMAT_JSON; $employee = new Employee(); $employee-> scenario = Employee::SCENARIO_CREATE; $employee->attributes = \Yii::$app->request->post(); if ($employee->validate()) { return array('status'=> true, 'data' => 'Employee Created Sussessfully'); } else { return array('status'=> false, 'data'=>$employee->getErrors()); } //return array('status'=> true); } Now when I run the API in Postman. I got the following result.
Though I have entered all the required fields data still it gives me false status
Any help would be highly appreciated
