问题描述
public function __construct(string $login,string $mdp,string $name,string $first_name,string $email,Company $company,bool $active = true,?Collection $groups = null,?Collection $team = null)
我想将$ team参数设置为null,因此默认值为空ArrayCollection
:
public function __construct(string $login,?Collection $team = null){
// -- 2 lines --
$this
// -- 7 lines --
->setTeam($team ?: new ArrayCollection());
}
所以我把我的装置写成:
# ./fixtures/UserFixtures.yaml
App\Entity\User:
user{1..1000}:
__construct:
login (unique): '<username()>'
mdp: "0000"
name: <name(null)>
first_name: <firstName(randomElement(array(null,'male','female')))>
email (unique): $name.$first_name@<freeEmailDomain()>
company: '@company_*'
active: '<boolean(99)>'
groups: '<numberBetween(1,10)>x @group_user*'
team: NULL
但是我仍然不明白如何放置一个空值。
我不能省略team
参数。
而且我不能将__construct设置为false,因为通过构造函数而不是setter定义参数很方便。另外,如果我不使用__construct,那么Alice不知道如何将数组转换为ArrayCollection。
我想要传递空值的最简单方法,或者向ALice指示我要使用默认值。
这实际上不起作用,我收到此消息:
[TypeError]
传递给App \ Entity \ User :: __ construct()的参数8必须是Doctrine \ Common \ Collections \ Collection的实例,或者为空,给定数组,在C:\ wamp64 \ www \ Hanff \ vendor \ nelmio \ alice \ src中调用\ Gen
第51行上的erator \ Instantiator \ Chainable \ NoCallerMethodCallInstantiator.PHP
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)