Yii learning 3 Use gii to implement CRUD operations

Source: Internet
Author: User
??? 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 NameIn the input box, entertbl_user. InModel ClassIn the input box, enterUser. Then clickPreviewButton. The new file to be generated is displayed here. Click nowGenerateButton. AUser.phpWill be generatedprotected/modelsDirectory. As described later,UserModel 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
?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.