生成文件类型
root@2e7ca4e64edf:/var/www/swoft# php bin/swoft gen
描述:生成常用应用内置模板类用法:gen:{command} [arguments] [options]命令:command 生成CLI命令控制器类controller 生成HTTP控制器类websocket 生成WebSocket控制器类rpcService 生成RPC服务类listener 生成一个事件监听器类middleware 生成HTTP中间件类task 生成用户任务类process 生成用户进程类entity 生成数据库实体类选项:-h, --help 显示命令组或专用命令操作的帮助信息
可通过php bin/swoft gen:{command} -h查看命令帮助信息
生成HTTP控制器类
root@2e7ca4e64edf:/var/www/swoft# php bin/swoft gen:controller -h
描述:生成HTTP控制器类用法:bin/swoft gen:controller CLASS_NAME SAVE_DIR [--option ...]参数:name 类名,无需后缀和文件扩展名dir 类文件保存目录,默认@app/Controllers选项:-y, --yes BOOL 文件生成写入时无需确认,默认为假-o, --override BOOL 强制覆盖已存在的文件,默认为假-n, --namespace STRING 类的命名空间,默认为App\Controllers--rest BOOL 类包含增删改查操作方法,默认假--prefix STRING 类路由的前缀,默认为类名--suffix STRING 类名后缀,默认为Controller--tpl-file STRING 模板文件名称,默认为command.stub--tpl-dir STRING 模板文件目录路径,默认为devtool/res/templates示例:bin/swoft gen:controller demo --prefix /demo -y Gen DemoController class to `@app/Controllers`bin/swoft gen:controller user --prefix /users --rest Gen UserController class to `@app/Controllers`(RESTFul type)
生成HTTP中间件类
root@2e7ca4e64edf:/var/www/swoft# php bin/swoft middleware -h
描述:生成HTTP中间件类用法:bin/swoft gen:middleware CLASS_NAME SAVE_DIR [--option ...]参数:name 类名,无需后缀和文件扩展名dir 类文件保存目录,默认@app/Middlewares选项:-y, --yes BOOL 文件生成写入时无需确认,默认为假-o, --override BOOL 强制覆盖已存在的文件,默认为假-n, --namespace STRING 类的命名空间,默认为App\Middlewares--suffix STRING 类名后缀,默认为Middleware--tpl-file STRING 模板文件名称,默认为middleware.stub--tpl-dir STRING 模板文件目录路径,默认为devtool/res/templates示例:bin/swoft gen:middleware demo 为@app/Middlewares生成DemoMiddleware类
生成数据库实体类
root@2e7ca4e64edf:/var/www/swoft# php bin/swoft entity -h
描述:生成实体类用法:bin/swoft gen:entity -d test [--option ...]选项:-d, --database STRING Must to set database. `,` symbol is used to separated by multiple databases-i, --include STRING Set the included tables, `,` symbol is used to separated by multiple tables. default is: all tables-e, --exclude STRING Set the excluded tables, `,` symbol is used to separated by multiple tables. default is: empty-p, --path STRING Specified entity generation path, default is: @app/Models/Entity--driver STRING Specify database driver(mysql/pgsql/mongodb), default is: mysql--table-prefix STRING Specify the table prefix that needs to be removed, default is: empty--field-prefix STRING Specify the field prefix that needs to be removed, default is: empty--tpl-file STRING The template file name. default is: entity.stub--tpl-dir STRING The template file dir path.(default: devtool/res/templates)示例:bin/swoft gen:entity -d test 为`@app/Models/Entity`生成DemoProcess类
创建数据实体
root@2e7ca4e64edf:/var/www/swoft# php bin/swoft entity:create -h
描述:通过数据表结构自动创建数据实体文件用法:entity:create -d[|--database] <database>entity:create -d[|--database] <database> [table]entity:create -d[|--database] <database> -i[|--include] <table>entity:create -d[|--database] <database> -i[|--include] <table1,table2>entity:create -d[|--database] <database> -i[|--include] <table1,table2> -e[|--exclude] <table3>entity:create -d[|--database] <database> -i[|--include] <table1,table2> -e[|--exclude] <table3,table4>选项:-d 数据库--database 数据库-i 指定特定的数据表,多表之间用逗号分隔--include 指定特定的数据表,多表之间用逗号分隔-e 排除指定的数据表,多表之间用逗号分隔--exclude 排除指定的数据表,多表之间用逗号分隔--remove-table-prefix 去除表前缀--entity-file-path 实体路径(必须在以@app开头并且在app目录下存在的目录,否则将会重定向到@app/Models/Entity)示例:php bin/swoft entity:create -d test
例如:为test数据库中的web_account表创建对应实体类,创建成功会生成app/Models/Entity/WebAccount类文件。
$ php bin/swoft entity:create -d test web_account
