Entity generation

Entity generation, can quickly generate entity files, swoft provides a simple and easy to use generation method. Currently officially only supports mysql entity generation, other types of database reference official examples


Use composer install composer require swoft/devtool


php bin/swoft entity:gen

php bin/swoft entity:c

php bin/swoft entity:create [tableName] [--pool=xx] [--path=xx] [--table_prefix=xx] [--field_prefix=xxx] [--exc=xxx] [--td=xxx] [-y]

These three names are a meaning.

You can use php bin/swoft entity:c -h view the specific command help documentation.

  • tableName specifies the data table of the generated entity. If it is empty, it will generate all matching table entities. You can also use --table=tableName to specify the data table name. Multiple tables are used , separated. If the data table prefix is set, tableName should not be used. Bring the table prefix.
  • Pool specifies the database connection pool, the default use db.pool connection pool
  • path generation paths entities support alias way transmission path, the default path to create a solid @app/Model/Entity such as: @app/Model/Entity in @app will resolve to the absolute path of the project.
  • Table_prefix is generated according to the data table prefix, abbreviated as tp , this parameter is not restricted by the parameters in db. The underlying prefix will match the table prefix by like
  • Field_prefix removes the field name prefix, abbreviated as fp , for example, the database field name t_name , when adding the entity, add --fp=t_ , and the generated entity attribute name is name .
  • Exc does not expect to generate the data table name, use the scene, for example, you need to generate all the entity parts table, do not want to generate the entity, you can use it to use multiple tables , separate
  • Td specifies the path of the generated template to support the alias mode delivery path. The default template path used is '@devtool/devtool/resource/template'
  • yDo not need to confirm the generated file, the -y parameter will directly generate the file will not confirm the prompt

pay attention

If the prefix table prefix configuration exists in the db configuration in the connection pool, the generated entity name will automatically remove the table prefix, where [tableName] , --table , [--exc=xxx] two parameters when querying the 数据表 . Automatically will bring the table prefix.

Please check whether the charset parameter of db is configured, otherwise the entity Chinese comment will be garbled.