简体   繁体   English

Symfony2可捕获的致命错误:参数1传递给实体可捕获的致命错误:参数1传递给实体

[英]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.

相关问题 在Symfony2中上载文件:可捕获的致命错误:参数1传递给 - Upload file in Symfony2: Catchable Fatal Error: Argument 1 passed to 可捕获的致命错误:参数1传递给 - Catchable Fatal Error: Argument 1 passed to Symfony 2嵌入式表单:可捕获的致命错误:传递给Entity的参数1 :: addProperty必须是XX \\ MyClass的一个实例,给出的数组 - Symfony 2 Embedded Forms: Catchable Fatal Error: Argument 1 passed to Entity::addProperty must be an instance of XX\MyClass, array given 可捕获的致命错误:传递给\\ Entity \\ Image :: setFile()的参数1必须是Symfony \\ Component \\ HttpFoundation \\ File \\ UploadedFile的实例, - Catchable Fatal Error: Argument 1 passed to \Entity\Image::setFile() must be an instance of Symfony\Component\HttpFoundation\File\UploadedFile, 可捕获的致命错误:参数1传递给CorenlpAdapter :: getOutput() - Catchable fatal error: Argument 1 passed to CorenlpAdapter::getOutput() Symfony服务容器-可捕获的致命错误-传递给构造的参数 - Symfony service container - Catchable Fatal Error - Argument passed to construct 可捕获的致命错误:参数1传递给? Symfony2.1 - Catchable Fatal Error: Argument 1 passed to ? Symfony2.1 Symfony2:ContextErrorException:可捕获的致命错误:传递给[…] :: __ construct()的参数1必须实现接口[…]没有给出 - Symfony2: ContextErrorException: Catchable Fatal Error: Argument 1 passed to […]::__construct() must implement interface […] none given 椭圆曲线密码术PHP:可捕获的致命错误参数1传递给__construct() - Elliptic Curve Cryptography PHP: catchable fatal error argument 1 passed to __construct() ZF 2:可捕获的致命错误:参数1传递给Zend \\ View \\ HelperPluginManager - ZF 2 :Catchable fatal error: Argument 1 passed to Zend\View\HelperPluginManager
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM