1. Create a simple MySQL database. For example I use yiicode as database name and user as table. See the attributes as follows:
Field | Type | Lenght/Values | Exrta | Primary |
id | int | - | auto_increment | Yes |
name | varchar | 60 | - | - |
address | varchar | 200 | - | - |
website | varchar | 100 | - | - |
varchar | 50 | - | - |
To make it, open http://localhost/xampp/, click on phpMyAdmin, click Databases, on the columns Create a new database typing demo, and click create. After that click on the SQL and create a user table by entering the following SQL command:
CREATE TABLE user ( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(60) NOT NULL, address VARCHAR(200) NOT NULL, website VARCHAR(100) NOT NULL, email VARCHAR(50) NOT NULL );
Typing in the Table Name * is tbl_user and in the Model Class * is User
You can see PHP code by click Preview button and the models\User.php. This code will be automatically stored in the xampp \ htdocs \ yourappname \ protected \ models \ User.php.
After it, click the Generate button
If successful will appear in the following:
The code has been generated successfully.That means you have successfully created a model to perform CRUD operations.
Generating code using template “xampp\htdocs\yii\framework\gii\generators\model\templates\default”…
generated models\User.php
done!