gpt4 book ai didi

symfony - Alice Faker 库从数组中随机选择

转载 作者:行者123 更新时间:2023-12-03 21:29:06 24 4
gpt4 key购买 nike

我正在尝试使用 AliceBundle 生成虚拟数据对于 Symfony 框架。除了我正在寻找一种方法将数组中的数据随机分配给名为 type 的属性之外,一切似乎都运行良好。 .看着faker library我可以看到我可以使用 randomElement($array = array ('a','b','c')) 生成它

我正在尝试将其转换为 YML我认为这相当于

<randomElement(['a','b','c'])>

但这会产生错误

[Nelmio\Alice\Throwable\Exception\FixtureBuilder\ExpressionLanguage\LexException] Could not lex the value "['a'".



这是我的完整 yml
AppBundle\Entity\Job:
job{1..5}:
title: <jobTitle()>
description: <paragraph(3)>
length: "3_months_full_time"
type: <randomElement(['a','b','c'])>
bonus: <paragraph(3)>
expired_at: "2016-12-21"
job_user: "@emp*"

最佳答案

这对我有用:

parameters:
profileArray: ['PUBLIC', 'PRIVATE', 'AUTHENTICATED']

JobPlatform\AppBundle\Entity\Profile:
profiles_{1..100}:
user: '@user_<current()>'
visibility: <randomElement($profileArray)>

关于symfony - Alice Faker 库从数组中随机选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41262741/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com