一键生成CRUD
在FastAdmin中可以快速的一键生成CRUD,自动生成后台的控制器、模型、视图、JS、语言包、菜单、回收站等。
准备工作
在数据库中默认有一个fa_test数据表可供参考,也可新建一个数据表,编辑好表字段结构,并且一定写上字段注释和表注释,相关数据表字段的设计要求可以参考数据库章节。FastAdmin在生成CRUD时会根据字段属性、字段注释、表注释自动生成语言包、组件和排版。
温馨提示
请确保你设计的表有且只有一个主键,不支持复合主键。
请确保php所在的目录已经加入到系统环境变量,否则会提示找不到该命令。
下面以 fa_test 数据表为例,打开命令行控制台进入到你的站点根目录,也就是think文件所在的目录,进行执行命令。
常用命令
//生成fa_test表的CRUDphp think crud -t test//生成fa_test表的CRUD且一键生成菜单php think crud -t test -u 1//删除fa_test表生成的CRUDphp think crud -t test -d 1//生成fa_test表的CRUD且控制器生成在二级目录下php think crud -t test -c mydir/test//删除fa_test表生成的二级目录的CRUDphp think crud -t test -c mydir/test -d 1//生成fa_test_log表的CRUD且生成对应的控制器为testlogphp think crud -t test_log -c testlog//生成fa_test表的CRUD且对应的模型名为testmodelphp think crud -t test -m testmodel//生成fa_test表的CRUD且生成关联模型category,外链为category_id,关联表主键为idphp think crud -t test -r category -k category_id -p id//生成fa_test表的CRUD且所有以list或data结尾的字段都生成复选框php think crud -t test --setcheckboxsuffix=list --setcheckboxsuffix=data//生成fa_test表的CRUD且所有以image和img结尾的字段都生成图片上传组件php think crud -t test --imagefield=image --imagefield=img//关联多个表,参数传递时请按顺序依次传递,支持以下几个参数relation/relationmodel/relationforeignkey/relationprimarykey/relationfields/relationmodephp think crud -t test --relation=category --relation=admin --relationforeignkey=category_id --relationforeignkey=admin_id//生成v_phealth_db2数据库下的fa_test表的CRUDphp think crud -t test --db=v_phealth_db2