保存Symfony2的实体形式我有一个城市添加形式:与实体领域
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()
;
但我不确定 - 这是正确的吗?
,你能告诉我们你的实体?你的桌子之间有链接吗? – Snroki 2013-03-13 12:10:23
而不是在标题内写*解*,你可以发布答案并接受它吗? – j0k 2013-03-13 14:02:19
@ j0k,我不能在帖子后的6个帖子中回复我的问题,所以我在标题中写了Solved。并将决定链接设置为内容。 – Salavat 2013-03-14 07:23:33