尝试更新实体时出现以下异常:
The form's view data is expected to be of type scalar, array or an instance of \ArrayAccess, but is an instance of class Proxies__CG__\Acme\DemoBundle\Entity\TicketCategory. You can avoid this error by setting the "data_class" option to "Proxies__CG__\Acme\DemoBundle\Entity\TicketCategory" or by adding a view transformer that transforms an instance of class Proxies__CG__\Acme\DemoBundle\Entity\TicketCategory to scalar, array or an instance of \ArrayAccess.
创建的时候没有问题,关系OK。但是,在更新时,出现了这个奇怪的异常。我的实体设置如下:
class Ticket
{
// ...
/**
* @var TicketCategory
*
* @ORM\ManyToOne(targetEntity="TicketCategory")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id")
*/
protected $category;
// ...
}
class TicketCategory
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string $title
*
* @ORM\Column(name="title", type="string", length=255)
* @Assert\NotBlank()
*/
private $title;
// ...
}
形式
class TicketType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title', 'text', array(
'error_bubbling' => true,
)
)
->add('category', 'text', array(
'error_bubbling' => true,
)
)
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Acme\DemoBundle\Entity\Ticket',
'csrf_protection' => false,
));
}
public function getName()
{
return '';
}
}
有什么想法吗,伙计们?