Symfony2的形状误差(symfony2 form error)

2019-09-17 18:51发布

The form's view data is expected to be of type scalar, array or an instance of \ArrayAccess, 
but is an instance of class Ecs\CrmBundle\Entity\Customer. 

是我在浏览器中得到的错误..

表单代码:

<?php

namespace Ecs\CrmBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class CustomerDefaultConfigType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name')
            ->add('customerStatus')
            ->add('tags', null, array('multiple' => true, 'property' => 'tag_name'))
        ;
    }

    public function getName()
    {
        return 'ecs_crmbundle_customerdefaultconfigtype';
    }
}

和控制器操作:

<?php

namespace Ecs\CrmBundle\Controller;

use Ecs\CrmBundle\Entity\CustomerDefaultConfig;
use Ecs\CrmBundle\Form\CustomerDefaultConfigType;
    public function newAction()
        {
            $entity = new CustomerDefaultConfig();
            $form   = $this->createForm(new CustomerDefaultConfigType(), $entity);

            return $this->render('EcsCrmBundle:CustomerDefaultConfig:new.html.twig', array(
                'entity' => $entity,
                'form'   => $form->createView()
            ));
        }

这是使用symfony2.1与作曲家...如何得到这个工作任何想法?

Answer 1:

自从上次形式的重构,你必须指定的data_classsetDefaultOptions方法在你的类型。

见这里 (搜索data_class )。

编辑:正确链接



文章来源: symfony2 form error