symfony2 form error

本秂侑毒 提交于 2019-12-22 10:12:55

问题


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. 

Is the error I get in my browser..

FORM CODE:

<?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';
    }
}

and the controller Action:

<?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()
            ));
        }

This is using symfony2.1 with composer... Any ideas on how to get this working?


回答1:


Since the last form refactoring, you have to specified the data_class in the setDefaultOptions method in your type.

See here (search for data_class).

Edit: Correct link



来源:https://stackoverflow.com/questions/10903461/symfony2-form-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!