Create (Insert) Record
To insert the records in the database, following steps are there. We have named our Yii2 folder as create.
Step 1 Create Model file
Create a model file child.php in frontend/models folder.
Look at the above code,
- \yii\db\ActiveRecord is used to create a model file.
- In function tableName put the table name you are using.
- Function rules define the inputs of your table.
Step 2 Create Controllers file
Create a controller file ChildController.php in frontend/controllers folder.
Step 3 Create View file
Create a view folder child in frontend/views folder. Then create a file create.php in frontend/views/child folder.
Now create a file child_view.php in frontend/views/child folder.
Step 4 Run it
Now run your application on your browser with the following URL.
Look at the above snpashot, after filling all the fields click on Create button and your data will be inserted into the database.
You can check it in the database from your phpmyadmin.