PHPackages                             topphp/topphp-generate - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. topphp/topphp-generate

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

topphp/topphp-generate
======================

PHP生成工具

v1.0.6(2y ago)19711MITSmartyPHP &gt;=7.2

Since Mar 8Pushed 2y ago1 watchersCompare

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

READMEChangelog (7)Dependencies (4)Versions (8)Used By (1)

topphp-generate
===============

[](#topphp-generate)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0eccfc128623abc3b824f00d6e907f0b98c81ca93d2d1f4b30a6b029d52baf3c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f707068702f746f707068702d67656e65726174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/topphp/topphp-generate)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/66d88cc97888b45273af74e05cc13315f08d1e5aa772ae9bd889fa2d5dadc5a4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f746f707068702f746f707068702d67656e65726174652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/topphp/topphp-generate)[![Coverage Status](https://camo.githubusercontent.com/8d38b2230cb1021b3d90c636c95b76c08f093df46653226227960686d547fec5/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f746f707068702f746f707068702d67656e65726174652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/topphp/topphp-generate/code-structure)[![Quality Score](https://camo.githubusercontent.com/eeb70c482f865340fa61bf2f3801732df299ace831b20cf310506a55243791bb/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f746f707068702f746f707068702d67656e65726174652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/topphp/topphp-generate)[![Total Downloads](https://camo.githubusercontent.com/e02fe96f9cdba5b1b8c3518dbb3a11986aca399d0ef17ff26c9496c0bb581ea5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f707068702f746f707068702d67656e65726174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/topphp/topphp-generate)

生成器
===

[](#生成器)

可快速生成thinkphp的模型类,继承自 think\\Model

版本说明
====

[](#版本说明)

现代的PHP组件都使用语义版本方案(), 版本号由三个点(.)分数字组成(例如:1.13.2).第一个数字是主版本号,如果PHP组件更新破坏了向后兼容性,会提升主版本号. 第二个数字是次版本号,如果PHP组件小幅更新了功能,而且没有破坏向后兼容性,会提升次版本号. 第三个数字(即最后一个数字)是修订版本号,如果PHP组件修正了向后兼容的缺陷,会提升修订版本号.

Structure
---------

[](#structure)

> 组件结构

```
bin/
build/
docs/
config/
src/
tests/
vendor/

```

Install
-------

[](#install)

Via Composer

```
$ composer require topphp/topphp-generate
```

Usage
-----

[](#usage)

需要先配置数据库信息 `config/database.php` 后进行命令行生成

```
php think gen:db
注意事项：
    1、自动生成：在topphp骨架里，多应用情况下，gen:db组件会根据你是否创建了对应的应用模块（如admin）下的model的文件夹来判断是否自动创建对应的model文件
    2、创建规范：应用模块（如admin）下的model文件统一会继承app/model/entity下的模型实体类,并全部以Dao.php结尾（此Dao层主要用于编写数据库业务）
    3、添加新的表：如果开发过程中需要添加新的数据表，可以执行 php think gen:db 进行自动更新模型实体类与模型Dao
    4、特别说明：
          a、每次执行 php think gen:db 模型实体类都会重置一遍，所以请不要直接编辑操作模型实体类
          b、每次执行 php think gen:db 对于已存在的模型Dao不会清空代码，对于不存在的模型Dao会自动创建（例如中途添加新的数据表场景）。
          c、每次执行 php think gen:db 以后使用传统环境（apache或nginx）部署在Linux系统下的注意统一修改一次文件夹权限（如：chown -R www:www www.domain.com/）

BaseModel 基础模型操作类
  Tips：提供模型操作的基本快捷方法，提升模型操作代码复用率，方便开发，包含如下方法：
       a、分页配置（用于自动构造TP6分页参数）protected getPaginateConfig()
       b、获取资源数据指定列的数组 protected getSourceColumn()
       c、数组分页 protected dataPage()

       // 以下为公共方法
       a、获取模型抛出的异常报错 getModelError()
       b、获取当前模型表所有字段名 getTableFieldName()
       c、新增数据 add()
       d、批量新增数据 addAll()
       e、大数据量批量新增（支持分批插入，一般应用于插入数据超千条场景） addLimitAll()
       f、编辑数据 edit()
       g、更新指定字段值（支持主键更新） updateField()
       h、指定字段自增（支持主键查询） fieldInc()
       i、指定字段自减（支持主键查询） fieldDec()
       j、指定字段自增/自减（支持主键查询，支持多字段步进处理） fieldStep()
       k、多条件批量更新（支持主键批量更新） updateAll()
       l、多条件批量更新（原生where查询） updateAllRaw()
       m、删除数据（支持主键删除，支持多条件删除，支持软删除） remove()
       n、删除数据（原生where查询，不支持直接传入主键id值删除，其他规则同remove） removeRaw()
       o、查询链式（支持主键查询，支持TP链式操作，融合软删除） queryChain()
       p、查询字段值（支持主键查询，支持select查询返回二维数组，默认find查询） findField()
       q、查询一条（支持主键查询，支持select查询返回二维数组，默认select查询） selectOne()
       r、查询所有（支持主键查询，支持排除字段） selectAll()
       s、查询排序（支持主键查询，支持原生SQL语句Order排序，支持Limit限制条数） selectSort()
       t、查询首条数据（支持前Limit条） selectFirst()
       u、查询最后一条数据（支持后Limit条） selectEnd()
       v、满足条件的数据随机返回（支持随机取Limit条） selectRand()
       w、查询某个字段的值相同的数据（同一张表指定字段值相同的数据，支持结果排序） selectSameField()
       x、查询指定字段值重复的记录（支持多字段匹配，支持结果排序） selectRepeat()
       y、查询指定字段值不重复的记录【仅查询不重复的】（支持多字段匹配，支持结果排序） selectNoRepeat()
       z、FIND_IN_SET查询（查询指定字段包含指定的值或字符串的数据集合） selectFieldInSet()
       I、FIND_IN_SET查询（查询指定字段在指定的集合的数据集合，效果类似于 field in (1,2,3,4,5) 的用法） selectFieldInList()
       II、查询List（支持分页，支持each回调） selectList()
       III、查询列（支持指定字段的值作为索引） selectColumn()

       // 以下为联查方法
       a、设置基础查询条件（用于简化基础alias、join和主表field） setBaseQuery()
       b、Join联查(innerJoin，如果表中有至少一个匹配，则返回行) selectJoin()
       c、leftJoin联查（即使右表中没有匹配，也从左表返回所有的行） selectLeftJoin()
       d、rightJoin联查（即使左表中没有匹配，也从右表返回所有的行） selectRightJoin()
       e、fullJoin联查（只要其中一个表中存在匹配，就返回行，Mysql数据库不支持） selectFullJoin()
       f、一对多子查询（支持分页，支持主表、子表字段过滤，返回值类似TP的with查询返回） selectChild()
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [topphp](https://github.com/topphp)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 59.1% 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

Every ~229 days

Recently: every ~319 days

Total

7

Last Release

876d ago

PHP version history (2 changes)v1.0.0PHP ~7.2

v1.0.5PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/3774ddafd6cc1dbff3db41386611fac2236c095e12c9e99f1717da35ad792087?d=identicon)[topphp](/maintainers/topphp)

---

Top Contributors

[![go-sleep](https://avatars.githubusercontent.com/u/100214298?v=4)](https://github.com/go-sleep "go-sleep (13 commits)")[![344147805](https://avatars.githubusercontent.com/u/26813709?v=4)](https://github.com/344147805 "344147805 (7 commits)")[![sleep-go](https://avatars.githubusercontent.com/u/5858884?v=4)](https://github.com/sleep-go "sleep-go (2 commits)")

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/topphp-topphp-generate/health.svg)

```
[![Health](https://phpackages.com/badges/topphp-topphp-generate/health.svg)](https://phpackages.com/packages/topphp-topphp-generate)
```

###  Alternatives

[topthink/think-captcha

captcha package for thinkphp

132934.4k67](/packages/topthink-think-captcha)[topthink/think-worker

workerman extend for thinkphp

202227.2k9](/packages/topthink-think-worker)[crescat-io/saloon-sdk-generator

Simplified SDK Scaffolding for Saloon

13130.9k7](/packages/crescat-io-saloon-sdk-generator)[craftcms/generator

Craft CMS component generator

88377.0k38](/packages/craftcms-generator)[beacon-hq/bag

A comprehensive immutable value objects implementation

1789.1k3](/packages/beacon-hq-bag)[topthink/think-annotation

Annotation For ThinkPHP

4831.5k8](/packages/topthink-think-annotation)

PHPackages © 2026

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