-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()

しかし、よくわかりません。これでよろしいですか?

決定: Symfony/Doctrine: "Catchable Fatal Error: Object of class <type> could not convert to string" when persisting

4

2 に答える 2

1

回答: Symfony/Doctrine: 「キャッチ可能な致命的エラー: クラス <type> のオブジェクトを文字列に変換できませんでした」(persisting)

したがって、次のものを使用します。

/**
 * @var X\tBundle\Entity\Country;
 *
 * @ORM\ManyToOne(targetEntity="X\tBundle\Entity\Country")
 * @ORM\JoinColumn(name="country_id", referencedColumnName="id", nullable=false)
 */
public $country;
于 2013-03-14T07:34:00.173 に答える