[英]Symfony2 Catchable Fatal Error: Argument 1 passed to entity Catchable Fatal Error: Argument 1 passed to entity
I got this error and I'm stuck since many hours 我收到此错误,并且由于很多小时而陷入困境
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
I searched for this issue and lots of results came up but I wasn't capable to solve this issue. 我搜索了此问题,但结果很多,但我无法解决此问题。
I'm trying to integrate two entities in one form and I got my idea form this post Create 2 different entities with same form in Symfony 2 我正在尝试以一种形式集成两个实体,而我在这篇文章中得到了我的想法。 在Symfony 2中以相同的形式创建了2个不同的实体
Probably it's a silliness but I couldn't understood even the error. 也许这很愚蠢,但我什至不理解错误。 :(
:(
following a snipped of the main form 摘掉主要形式
//InYourMindType.php
class InYourMindType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('thinkFriend', new InYourMindFriendType)
//...
This is the "embedded" form: 这是“嵌入”形式:
//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';
}
The twig where the main form is called (then the embedded one) 称为主要形式的树枝(然后是嵌入的树枝)
<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) }}
Those forms belong to two different entities connected respectively by a many-to-one and one-to-many relationship. 这些形式属于分别通过多对一和一对多关系连接的两个不同实体。
If you need i post the entities just ask. 如果您需要我发布实体,请问。
Thanks a lot 非常感谢
Set data_class option for your InYourMindFriendType 为您的InYourMindFriendType设置data_class选项
Checkout http://symfony.com/doc/current/reference/forms/types/form.html#data-class 结帐http://symfony.com/doc/current/reference/forms/types/form.html#data-class
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.