您的位置:首页 > 编程语言 > PHP开发

yii2.0 使用 Gii 生成代码

2014-11-11 16:02 351 查看

开始 Gii

config/web.php
文件中会有以下配置代码:

$config = [ ... ];

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


}


这段配置的意思是如果当前是开发环境,应用会包含
gii
模块,模块类是 [[yii\gii\Module]]。

生成活动记录类

访问http://localhost/test2(项目名)/web/index.php?r=gii

选择 “Model Generator”

并像这样填写表单:

Table Name:
country

Model Class:
Country


生成 CRUD 代码

选择 Gii 中的 “CRUD Generator” (增删改查)去创建 CRUD 功能

Model Class:
app\models\Country

Search Model Class:
app\models\CountrySearch

Controller Class:
app\controllers\CountryController


尝试连接:http://localhost/test2/web/index.php?r=country/index
下面列出由 Gii 生成的文件

控制器:
controllers/CountryController.php

模型:
models/Country.php
models/CountrySearch.php

视图:
views/country/*.php
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: