Home > PHP Framework > YII > body text

What is gii in yii2?

青灯夜游
Release: 2020-07-24 10:25:46
Original
4415 people have browsed it

gii is an extension module in yii and is a good tool for rapid development; it automatically generates code through gii and leaves some common codes to the program to generate, which greatly reduces the developer's time cost. . The gii module can be enabled by configuring the "yii\base\Application::modules" property.

What is gii in yii2?

yii2 is a rapid development framework, in which the gii extension has to be said to be a great help. It automatically generates code through gii and integrates some common codes. Let the program generate it, which greatly reduces the developer's time cost.

yii2 gii enable

The gii module can be enabled by configuring the yii\base\Application::modules attribute. There will be the following configuration code in the config/web.php file:

$config = [ ... ];
if (YII_ENV_DEV) {
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = 'yii\gii\Module';
}
Copy after login

After checking, I found that my configuration is the same as above, but why can’t I access it? It turns out there is another configuration. The above configuration means that if it is currently a development environment, the application will include the gii module, and the module class is yii\gii\Module. Next, let's go to the application's entry script web/index.php, and you will see the following code

efined('YII_ENV') or define('YII_ENV', 'dev');
Copy after login

Set YII_ENV_DEV to true, ok, and you can access it.

Another point is to turn off the urlManager beautification

yii2 uses gii to generate code

This Gii extension is undoubtedly the fastest for yii2 A great help for development, using GII to generate code greatly saves development time and cost.

Build table

Create a new test table for test in the database (As shown below)

What is gii in yii2?

Model generation

1. Open the gii interface /index.php?r=gii or /gii (After beautifying the url)

What is gii in yii2?

2. Create the Model

First, click the start button under the Model generator to enter the model generation interface and enter the data table name test , enter model class (generally one will be automatically generated, you can also customize the model class name)

What is gii in yii2?

Then, click preview below, and the model to be generated will be listed

What is gii in yii2?

Finally, click generate to generate the model file. The following prompts that the generation is successful

What is gii in yii2?

Generate CRUD

Similarly, click CRUD Generator to create CRUD, which is the operation interface and function of adding, deleting, modifying, and checking. Enter the corresponding parameters (note: if the view path is not filled in, it will be generated in the default location)

What is gii in yii2?

Then, click preview to view the list of files to be generated (Note: If the corresponding control already exists, the diff below will be displayed, and you can choose to overwrite or retain it)

What is gii in yii2?

Finally click Generate to generate the corresponding CRUD file, and then you can view the corresponding page. It is so simple to complete the addition, deletion and modification of a data table to

What is gii in yii2?

Recommended related article tutorials: "yii Framework Tutorial", "PHP Tutorial"

The above is the detailed content of What is gii in yii2?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!