symfony2 表单错误 [英] symfony2 form error

查看:36
本文介绍了symfony2 表单错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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..

表格代码:

<?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 与作曲家一起使用...有关如何使其工作的任何想法吗?

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

推荐答案

自上次表单重构以来,您必须在类型中的 setDefaultOptions 方法中指定 data_class.

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

请参阅此处(搜索data_class).

正确链接

这篇关于symfony2 表单错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆