我收到此错误,我被困了很多小时
Catchable Fatal Error: Argument 1 passed to Thinking'ThinkBundle'Entity'InYourMind::setThinkFriend() must be an instance of Thinking'ThinkBundle'Entity'InYourMindFriend, array given, called in /var/www/html/thinkroulette/vars/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php on line 410 and defined
我搜索了这个问题,出现了很多结果,但我无法解决这个问题。
我正在尝试以一种形式集成两个实体,我从这篇文章中得到了我的想法在Symfony 2中创建2个具有相同形式的不同实体
可能这是一种愚蠢,但我甚至无法理解错误。 :(
在主窗体的截取之后
//InYourMindType.php
class InYourMindType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('thinkFriend', new InYourMindFriendType)
//...
这是"嵌入式"形式:
//InYourMindDriendType
class InYourMindFriendType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('email', 'email', array(
'label' => 'label_think_userEmail',
'required' => false,
'attr' => array(
'title' => 'label_think_userEmail',
'class' => 'form-control'
)
));
}
public function getName()
{
return 'thinkFriend';
}
称为主窗体的树枝(然后是嵌入的树枝)
<div class="form-group">
{{ form_label(t_form.title) }}
{{ form_widget(t_form.title) }}
{{ form_errors(t_form.title) }}
</div>
<div class="form-group">
{{ form_label(t_form.thinkFriend.email) }}
{{ form_widget(t_form.thinkFriend.email) }}
{{ form_errors(t_form.thinkFriend.email) }}
这些形式属于两个不同的实体,分别通过多对一和一对多关系连接。
如果您需要,我会发布实体,请询问。
多谢
为您的 InYourMindFriendType 设置data_class选项
结帐 http://symfony.com/doc/current/reference/forms/types/form.html#data-class