• yii框架之gii的使用


    Gii这个扩展无疑是yii2快速开发的一大助力,通过使用gii生成代码很大程序上节约了开发的时间成本,那么如何使用gii这个组件呢,下边简单介绍一下yii2中gii的一些常用功能

    1.首先建一张表

    CREATE TABLE `test` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `user` varchar(256) NOT NULL DEFAULT '' COMMENT '姓名',
      `age` int(10) NOT NULL DEFAULT '0' COMMENT '年龄',
      PRIMARY KEY (`id`),
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='测试表'

    2.修改配置

    打开config/web.php修改如下配置

    if (!YII_ENV_TEST) {
        // configuration adjustments for 'dev' environment
        $config['bootstrap'][] = 'debug';
        $config['modules']['debug'] = [
            'class' => 'yiidebugModule',
            'allowedIPs'=>['*']
        ];
    
        $config['bootstrap'][] = 'gii';
        $config['modules']['gii'] = [
            'class' => 'yiigiiModule',
            'allowedIPs'=>['*']
        ];
    }

    然后在web/index.php下修改,应用应处于开发模式下,按照上面的配置才会打开 Gii 模块

    defined('YII_ENV') or define('YII_ENV', 'dev');

    3.打开gii页面,打开gii的界面 /index.php?r=gii或者 /gii(url美化之后) ,试试这两种肯定会有一种能打开,http://127.0.0.1/index.php?r=gii 或 http://127.0.0.1/gii

    页面打开之后如下

    4.生成代码,根据提示可以生成代码了,model,controller等

    5.或者用命令行生成,如下

    php yii gii/model --ns=app\models --tableName=test --modelClass=Test
    php yii gii/crud --modelClass=app\models\Test --controllerClass=app\controllers\TestController

    参考:https://www.yii-china.com/post/detail/291.html

    https://www.jianshu.com/p/2e2d6142d18c

    https://www.php.cn/phpkj/yii/443495.html

    https://blog.csdn.net/qq_20757489/article/details/77522617

  • 相关阅读:
    从O(n^3) 到 O(n)求最大连续和
    冲刺博客NO.6
    冲刺博客NO.5
    冲刺博客NO.4
    冲刺博客NO.3
    冲刺博客NO.2
    冲刺博客NO.1
    结对开发:四则运算(网页版)
    课堂作业3
    软件工程概论02~ 四则运算
  • 原文地址:https://www.cnblogs.com/kumufengchun/p/13225616.html
Copyright © 2020-2023  润新知