PHPackages                             funson86/yii2-gii - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. funson86/yii2-gii

ActiveYii2-extension

funson86/yii2-gii
=================

Yii2 gii for chinese

0.0.1(11y ago)2249811Apache-2.0PHP

Since Jan 8Pushed 8y ago7 watchersCompare

[ Source](https://github.com/funson86/yii2-gii)[ Packagist](https://packagist.org/packages/funson86/yii2-gii)[ RSS](/packages/funson86-yii2-gii/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Yii2-gii for Chinese
====================

[](#yii2-gii-for-chinese)

主要针对中文和项目的优化

default模板
---------

[](#default模板)

### Model

[](#model)

1. 在model.php头部增加$labelList = \['type', 'kind'\]; 如果其他需要生成getXXXLabels函数会自动生成，适用于需要定义常量的字段。
2. 增加beforeSave和afterSave两个函数，默认为注释掉的
3. 增加model保存时自动附加时间和操作用户TimestampBehavior::className(),BlameableBehavior::className(),
4. 增加getImportFields和getExportFields两个函数，用于指定导入导出csv对应的类型，类型暂时支持relation/enum/int/text。‘\_id’默认为relation类型，自动转换为该类型的name；enum对应$labelList中所指定，自动对应getXxxLabels中标签；int对应字段类型为integer或boolean；其他为text类型。
5. 在controller.php头部增加$importPrimary，用来判定导入时候为新增数据还是更新数据，支持通过数组方式指定类型，类型和上述一致enum/relation/text/int/decimal。

### CRUD

[](#crud)

#### Controller

[](#controller)

1. 针对鉴权提供can函数
2. 对actionDelete增加软删除，即将状态设置为STATUS\_DELETE状态
3. search.php增加排序，默认按照create\_at降序，可启用按照sort\_order升序, create\_at降序
4. 增加import和export函数，对应controller-id/import和controller-id/export路由，如果需要对导入文件做严格的检查，修改if (false/*empty($result\[$i\]\[0\]) || empty($result\[$i\]\[1\])*/) { 部分代码。
5. 导入的模板需要放在backend/web/template/table.csv文件

#### Views

[](#views)

1. 在index.php \_form.php view.php文件的头部有$labelList = \['type', 'kind'\]; 在index中会使用标签以及生成下拉列表筛选， 表单中增加下拉列表 view中会转换成对应的标签
2. index、view中所有的‘\_at’结尾的字段转变成时间字符串，所有的‘\_by’会显示成user表中的username，且以这两个不会在表单中出现，自动使用model中的
3. 所有以‘\_id’结尾的字段，都会对前面的字段进行处理成相关model中的name字段，对于user表则显示为username字段。index、view中显示name内容，form表中显示成id=&gt;name下拉列表
4. 如果有‘status’字段，都会解析成common\\models\\Status中的标签。index、view中显示标签，form表变成下拉列表
5. 如果以‘\_status’结尾的字段，则会解析成当前model中对应的getXxxStatusLabels函数中的标签，form表变成下拉列表

### 数据表设计

[](#数据表设计)

1. 除parent\_id外，所有的以‘\_id’结尾的字段需要定义外键
2. 所有的状态使用‘status’或者以‘\_status’结尾
3. 最好加上created\_at，updated\_at，created\_by，updated\_by
4. 需要常量的字段在model.php index.php \_form.php view.php中添加到$labelList中

所有的表格最好以一下方式结尾

```
  `sort_order` int(11) NOT NULL DEFAULT '50',
  `status` int(11) NOT NULL DEFAULT '1',
  `created_at` int(11) NOT NULL DEFAULT '1',
  `updated_at` int(11) NOT NULL DEFAULT '1',
  `created_by` int(11) NOT NULL DEFAULT '1',
  `updated_by` int(11) NOT NULL DEFAULT '1',
```

一个常用的表：

```
CREATE TABLE `prefix_test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `parent_id` int(11) NOT NULL DEFAULT '0',
  `product_id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `content` text,
  `user_id` int(11) NOT NULL DEFAULT '0',
  `type` int(11) NOT NULL DEFAULT '1',
  `sort_order` int(11) NOT NULL DEFAULT '50',
  `status` int(11) NOT NULL DEFAULT '1',
  `created_at` int(11) NOT NULL DEFAULT '1',
  `updated_at` int(11) NOT NULL DEFAULT '1',
  `created_by` int(11) NOT NULL DEFAULT '1',
  `updated_by` int(11) NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`),
  KEY `parent_id` (`parent_id`),
  KEY `product_id` (`product_id`),
  KEY `created_at` (`created_at`),
  KEY `FK_test_plan_id` (`plan_id`),
  CONSTRAINT `FK_test_product_id` FOREIGN KEY (`product_id`) REFERENCES `prefix_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
```

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require funson86/yii2-gii "dev-master"

```

or add

```
"funson86/yii2-gii": "dev-master"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Once the extension is installed, simply use it in your code by :

在main-local.php中配置：

```
if (!YII_ENV_TEST) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = 'yii\debug\Module';

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'],
        'generators' => [ //here
            'crud' => [ //name generator
                'class' => 'yii\gii\generators\crud\Generator', //class generator
                'templates' => [ //setting for out templates
                    'funson86' => '@vendor/funson86/yii2-gii/crud/default', //name template => path to template
                ]
            ],
            'model' => [ //name generator
                'class' => 'yii\gii\generators\model\Generator', //class generator
                'templates' => [ //setting for out templates
                    'funson86' => '@vendor/funson86/yii2-gii/model/default', //name template => path to template
                ]
            ],
        ],
    ];
}
```

在gii新建模板时会多出一个选项。

如果要统一输出显示的日期时间格式，修改config/main.php

```
        'formatter' => [
            'dateFormat' => 'yyyy-MM-dd',
            'datetimeFormat' => 'yyyy-MM-dd HH:mm:ss',
            'decimalSeparator' => ',',
            'thousandSeparator' => ' ',
            'currencyCode' => 'EUR',
        ],
```

一些小技巧参考 [tips](tips.md)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4143d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bb4ef339ac2639cdbc690a4b3217c2bb910dcc407f342c743a3d9cfc142e3d29?d=identicon)[funson86](/maintainers/funson86)

---

Top Contributors

[![funson86](https://avatars.githubusercontent.com/u/6244263?v=4)](https://github.com/funson86 "funson86 (32 commits)")

---

Tags

yii2extensionblog

### Embed Badge

![Health badge](/badges/funson86-yii2-gii/health.svg)

```
[![Health](https://phpackages.com/badges/funson86-yii2-gii/health.svg)](https://phpackages.com/packages/funson86-yii2-gii)
```

###  Alternatives

[skeeks/cms

SkeekS CMS — control panel and tools based on php framework Yii2

13825.6k47](/packages/skeeks-cms)[akiraz2/yii2-blog

Simple, configurable blog module for Yii2 (post, comment, nested category, tags). + frontend, backend. + SEO! (Opengraph, Schema.org)

906.7k](/packages/akiraz2-yii2-blog)[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1452.6k](/packages/dmstr-yii2-cookie-consent)[richardfan1126/yii2-js-register

Yii2 widget to register JS into view

1357.2k7](/packages/richardfan1126-yii2-js-register)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
