Javatpoint Logo
Javatpoint Logo

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.

http://localhost/create/frontend/web/index.php?r=child/create

YII Insert record 1

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.

Next TopicRead Record





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA