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.
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'; }
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');
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)
Model generation
1. Open the gii interface /index.php?r=gii or /gii (After beautifying the url)
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)
Then, click preview below, and the model to be generated will be listed
Finally, click generate to generate the model file. The following prompts that the generation is successful
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)
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)
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
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!