delboy1978uk/generator

为Bone框架生成空白、控制器和数据库实体包模板

v1.3.8 2023-07-02 15:39 UTC

README

生成doctrine实体、服务、存储库和表单。

安装

Composer等

包生成

$ vendor/bin/generator entity
Entity and Service Generator

Enter the base namespace: Del\Animal
Enter the name of the entity: Unicorn

Create a field? (Y/n)
Enter the name of the field: name
What type of data does it hold? 
  [0] date
  [1] datetime
  [2] decimal
  [3] double
  [4] float
  [5] int
  [6] varchar
  [7] bool
 > 6
What length is the field? 30
Is the field nullable?  (Y/n)

Create another field? (Y/n)
Enter the name of the field: dob
What type of data does it hold? 
  [0] date
  [1] datetime
  [2] decimal
  [3] double
  [4] float
  [5] int
  [6] varchar
  [7] bool
 > 0
Is the field nullable?  (Y/n)

Create another field? (Y/n)
Enter the name of the field: isHungry
What type of data does it hold? 
  [0] date
  [1] datetime
  [2] decimal
  [3] double
  [4] float
  [5] int
  [6] varchar
  [7] bool
 > 7
Is the field nullable?  (Y/n)

Create another field? (Y/n)n

Successfully generated in build/5cd362ce88907.

运行数据库迁移

  • 复制 migrant-cfg.php.dist 移除 .dist 扩展名,然后用您的数据库详细信息进行编辑。
  • 创建迁移文件夹
  • 将构建文件夹的内容移动到您的项目或包的 src 目录下
  • 编辑Package类,设置实体路径,通常是 src/Entityvendor/vendorname/package/src/Entity
vendor/bin/migrant diff
vendor/bin/migrant migrate

用法

如果您正在使用 Del\Common,创建一个容器并添加该包。它将在 service.YourEntityName 键下可用。

如果不这样做,则创建Doctrine实体管理器并将其传递给服务构造函数。