2 回答

TA貢獻1893條經驗 獲得超10個贊
錯誤消息說明了您需要了解的所有信息。您正在嘗試將對象轉換為字符串。在本例中為 BookAuthor。我假設這些實體之間存在一對多或多對多的關系。在這種情況下,在 BookSeriesType 中,SeriesAuthor 應該是EntityType。

TA貢獻1853條經驗 獲得超18個贊
顯然我必須對表單生成器進行一些配置。
public function buildForm(FormBuilderInterface $builder, array $options)
? ? {
? ? ? ? $builder
? ? ? ? ? ? ->add('title')
? ? ? ? ? ? ->add('seriesAuthor', EntityType::class, [
? ? ? ? ? ? ? ? 'class' => BookAuthor::class,
? ? ? ? ? ? ? ? 'choice_label' => function(BookAuthor $author) {
? ? ? ? ? ? ? ? ? ? return sprintf('%s %s', $author->getFirstname(), $author->getLastname());
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? 'placeholder' => 'Choose an author'
? ? ? ? ? ? ])
? ? ? ? ? ? ->add('description')
? ? ? ? ? ? ->add('Submit', SubmitType::class)
? ? ? ? ;
? ? }
- 2 回答
- 0 關注
- 155 瀏覽
添加回答
舉報