phact-cmf-modules / filler
phact CMF 的填充模块
Requires
- php: ^7.1.3
- phact-cmf/phact: ^1.0.3
This package is auto-updated.
Last update: 2024-09-24 21:26:04 UTC
README
配置 (filler.php)
将其放入 app/config
<?php return [ \Modules\Catalog\Models\Category::class => [ 'scheme' => 'tree', 'dict' => 'categories', 'dictSettings' => [ 'title' => 'name' ], 'fields' => [ ], 'skip' => [], 'limit' => 100 ], \Modules\Catalog\Models\Product::class => [ 'scheme' => 'flat', 'fields' => [ 'category' => [ 'filter' => [ 'lft' => new \Phact\Orm\Expression('rgt - 1') ], 'exclude' => [] ], 'price' => [ 'from' => 1000, 'to' => 20000 ] ], 'skip' => [], 'limit' => 100 ] ];
命令
# php index.php Filler Fill
选项
schema - 可用 2 种模式 - 平面 ("flat") 和树 ("tree")
dict - 字典(字典路径,例如 "Modules.YourModule.dict.tree_dict"),对于树,默认可以指定 "categories" - 它将链接到 "Modules.Filler.dict.categories"
dictSettings - 重命名字典字段为我们需要的。例如对于 "categories" 字典 - 对象的名称是通过 "name" 属性指定的,而在我们的模型中是 "title"。定义 dictSettings
... 'dictSettings' => [ 'name' => 'title' ] ...
skip - 在生成时将被跳过的字段列表
limit - 生成对象的限制数量(当字典活动时,不适用)
fields - 生成字段的设置
我将列出字段类型及其设置
具有声明性选择的字段
将填充一个 choices 元素。如果字段可以是 null,则也可以应用 null 值
JsonField, SlugField, PositionField
这些字段将在生成时被忽略并填充为默认值
ForeignField
将填充为随机对象,类 modelClass,由字段指定
可用的设置
filter - 选择对象的 QuerySet 过滤器。默认:[]
exclude - 选择对象的 QuerySet 排除。默认:[]
FileField
将填充为文件夹中的随机文件
可用的设置
path - 用于填充的文件文件夹路径。默认:"Modules.Filler.files"
extensions - 要填充的扩展名列表。示例:['zip', 'pdf']。默认:null
ImageField
类似于 FileField,但默认路径不同:"Modules.Filler.images"
BooleanField
true 或 false,非常简单
DateField, DateTimeField, TimeField
将填充为随机的日期/时间值
可用的设置
from - 日期的文本表示,从该日期开始选择随机值。默认:"-100 days"
to - 日期的文本表示,到该日期选择随机值。默认:"+100 days"
EmailField
将填充为随机的电子邮件
TextField
将填充为随机的文本
可用的设置
fromWords - 最小单词数。默认:20
toWords - 最大单词数。默认:100
CharField
类似于 TextField,默认单词数从 2 到 5
IntField, FloatField, DecimalField
将填充为随机的值
可用的设置
from - 选择随机值的最小整数。默认:0
to - 选择随机值的最大整数。默认:1000