エンティティを分割する必要はありませんが、フォーム: 3 つのフォームを作成し、それぞれに広告エンティティから必要なプロパティを含めます。
あなたがする必要があります:
- コントローラー内のすべてのステップで $ad オブジェクトを永続化します (フラッシュしません)
- コントローラー内で転送するときに、 $ad オブジェクトを引数として渡します
- 最後のステップで $ad オブジェクトをフラッシュします
疑似コードでは、コントローラーは次のようになります。
public function newAdStep1() {
new Ad() // New instance of $ad
new formStep1($ad) // The first form containing only the ad text field
// The form was filled, manage it...
form->isValid()? {
persist($ad); // Persist the first part of your ad object
forward(newAdStep2, $ad) // Go on to step 2, your $ad object as an argument
}
// ... or display step1 to user
createView createAdStep1.html.twig('form' => $form);
}
public function newAdStep2($ad) {
new formStep2($ad); // Now the second form, containing the "contact" fields
isValid ? {
persist($ad)
forward(newAdStep3, $ad)
}
createView createAdStep2($form, $ad); // Your $ad object needs to be sent to the view
}
public function newAdStep3($ad) {
new formStep3($ad); // Third and last form, containing the (X,Y) fields
isValid ? {
$em->persist($ad);
$em->flush(); // Your instance of $ad can be stored in database now
return('success !');
}
return view createAdStep3($form, $ad);
}