首页 文章

使用实体字段保存symfony2实体表单

提问于
浏览
-1

我有一个城市添加表格:

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('name', null, array(
            'label' => 'City',
        ));
        $builder->add('country', 'genemu_jqueryautocompleter_entity', array(
            'class' => 'X\tBundle\Entity\Country',
            'property' => 'name',
            'route_name' => 'ajax_country',
            'required' => true,
            'label' => 'Country',
        ));
    }

国家是一个实体 . 当我提交此表单时 - S2返回错误: cannot save because cannot convert Object to String

为此,我使用魔法 __toString() 并返回 (string)$this->getId() ;

但我不确定 - 这是对的吗?

Desicion: Symfony/Doctrine: "Catchable Fatal Error: Object of class <type> could not be converted to string" when persisting

2 回答

相关问题