Yii 2 框架的 Gii 扩展 - 复杂模型生成器
1.2.2
2016-02-11 05:28 UTC
Requires
- dmstr/yii2-bootstrap: *
- yiisoft/yii2-gii: >=2.0.1
README
为 Yii2 框架的代码生成器 Gii 扩展模型
这是什么?
Hii 为复杂的数据库模型提供自动模型生成。它支持
- 两个模型之间许多关系
- ‘name2other_name’ 数据库表名
- 级联模型结构
models
|- base / model.php <- this one has automaticly generated relations
|- model.php
- 通过在 'customRelations' 中设置,可以设置自我关系
- 自动生成静态方法 findBy{UniqueField}
安装
安装此扩展的首选方式是通过 composer。
composer.phar require grzegorz-pierzakowski/hii:"*"
or you can add this into the composer.json:
"grzegorz-pierzakowski/hii": "*"
如果启用了 Gii 模块,Hii 模型生成器将在应用程序引导过程中自动注册
使用自定义选项(在 params 中,直到 Yii2 允许将配置传递给生成器为止)
$config['params']['hii-model'] = [
// put your custom pairs of 'table' => 'ModelName' map here
'tableModelMap' => [
],
// put your pairs of 'column_name' => 'RelationSuffix' map here
// this will allow to generate more than one relation between 2 models
'customRelations' => [
]
]
使用方法
访问您的应用程序的 Gii(例如,index.php?r=gii
并从主菜单屏幕中选择 Hii 模型。
有关基本使用说明,请参阅 Yii2 指南中的 Gii 部分。
假设您有一个由 Group 对象表示的 ggroup 表,ggroup 有 user_id 和 user_last_id 列。您有两个与 User 对象的关系。如果将项目设置为
$config['params']['hii-model'] = [
'customRelations' => [
'last_user_id' => 'Last'
],
'tableModelMap' => [
'ggroup' => 'Group'
]
]
将发生魔法般的事情,您的模型将具有以下关系
Group User->myGroup
Group User->myGroupLast
User Group->lastUser
User Group->user