??? GII is a visual code generation module of YII, which is much easier and quicker than using the command line .??? The latest YII comes with the GII module, so you don't have to install it any more. It is not enabled by default. You only need to configure it .??? It is still the pretectedconfigmain. php file ??? Modulesarray (??????? Uncommentthefollowing
??? GII is a visual code generation module of YII, which is much easier and quicker than using the command line .??? The latest YII comes with the GII module, so you don't have to install it any more. It is not enabled by default. You only need to configure it .??? It is still the pretected/config/main. php file ??? Modules = array (??????? // Uncomment the following
??? GII is a visual code generation module of YII, which is much easier and quicker than using the command line.
??? The latest YII comes with the GII module, so you do not have to install it. It is not enabled by default. You only need to configure it.
??? Still the pretected/config/main. php file
??? 'Modules' => array (
??????? // Uncomment the following to enable the Gii tool
??
?? ???? 'Giii '=> array (
?????? ? 'Class' => 'System. gii. GiiModule ',
?????? ? 'Password' => '000000 ′,
?????? ? // If removed, Gii defaults to localhost only. Edit carefully to taste.
?????? ? 'Ipfilters '=> array ('127. 0.0.1', ': 1 ′),
???? ),
??? ? You can remove the comment to use gii. The password is the password, and the ipFilters is the IP address restriction. if you remove the comment, the local machine is restricted. At the time of release, you can change this IP address to the IP address of the local machine to ensure security. However, in China, most of them are dynamic IP addresses. It is better to disable GII directly if you change the IP address frequently.
???? Create a table in the database for testing. You can directly import protected/data/schema. mysql. SQL, including a tb_user table and test data.
????? Openhttp://localhost/index.php?r=gii
??? Enter the password to generate the code.
??? Generate User model
???? After logging in, click the linkModel Generator
. The following model generation page is displayed,
???? Model Generator
InTable Name
In the input box, entertbl_user
. InModel Class
In the input box, enterUser
. Then clickPreview
Button. The new file to be generated is displayed here. Click nowGenerate
Button. AUser.php
Will be generatedprotected/models
Directory. As described later,User
Model classes allow us to access data tables in an object-oriented mannertbl_user
.
Generate CRUD code
After creating the model class, we will generate and execute CRUD ?? (Create, read, update, and delete) operation code. SelectCrud Generator
, As shown below,
Enter
Http: // localhost/index. php? R = user.
Of course, if you are not idle, you can also run the command to generate
Switch to the protected directory of the current project.
cd E:\wwwroot\test\protected
Start command
yiic shell E:\wwwroot\test\index.php
Generate model
model User tb_user
Generate crud
crud User
?