yii2.0 使用 Gii 生成代码

开始 Gii

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

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

  
  
  1. }

这段配置的意思是如果当前是开发环境,应用会包含 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.phpmodels/CountrySearch.php
  • 视图:views/country/*.php

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值