gpt4 book ai didi

symfony - EntityChoiceList.php 第 273 行中 isset 或空中的偏移类型非法

转载 作者:行者123 更新时间:2023-12-02 01:19:38 26 4
gpt4 key购买 nike

在我的 Symfony2 项目中,我尝试动态生成表单类型中使用的实体,绕过查询生成器等的使用。

对于实体选择属性,我提供了要使用的实体数组。在页面加载时,一切看起来都很好并且显示了正确的内容。但是在提交表单时我得到了

Illegal offset type in isset or empty in EntityChoiceList.php line 273

at ErrorHandler ->handle ('2', 'Illegal offset type in isset or empty',
'..../Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php', '273', array('key' => object(myEntity))) in ..../Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php at line 273
.....
return isset($entities[$key]) ? $entities[$key] : null;
.....

令我困惑的是,如果我添加 var_dump(isset($this->entities[$key]));exit;在这一行上方,我返回了“bool(true)”,这对我来说意味着 key 确实存在。

作为背景,我尝试扩展 EntityType,以便在我的项目中轻松使用并添加:

public function getDefaultOptions(array $options)
{
$defaultOptions = array(
'em' => null,
'class' => 'Acme\TestBundle\Entity\myEntity',
'property' => null,
'query_builder' => null,
'choices' => $this->myEntityArray,
);

$options = array_replace($defaultOptions, $options);
$defaults = parent::getDefaultOptions($options);
return $defaults;
}

有谁知道为什么我会收到此错误,或者我尝试将一组实体传递给选择时是否完全错误地解决了我的问题?

最佳答案

如果您在尝试从 ArrayCollection 中删除元素时遇到此问题,可能是因为您输入了:

$list->remove($item) 而不是 $list->removeElement($item)

关于symfony - EntityChoiceList.php 第 273 行中 isset 或空中的偏移类型非法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10189541/

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