[設置]集實體參數
- Symfony的3
- BoxEntity:[ID,名稱]
- CandyEntity:[ID,名稱]
[問題]
目前,在創建新糖果時,我必須選擇一個盒子作爲父實體。
事情是,我希望這個選擇是自動化的。
該框已經在數據庫中註冊,並且會話持有當前框參數以方便查找。
但是我不知道如何在數據發佈後將其應用於糖果實體。
[FILES]
的appbundle /控制器/ CandyController.php
public function newAction(Request $request) {
$$candy= new Candy();
$form = $this->createForm('AppBundle\Form\CandyType', $conference);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($candy);
$em->flush();
return $this->redirectToRoute('candy_show', array('id' => $candy->getId()));
}
return $this->render('candy/new.html.twig', array(
'candy' => $candy,
'form' => $form->createView(),
));
}
的appbundle /形式/ CandyType.php
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('nom')
->add('box'); //Remove from form, and set manually
}
我沒有read this page,但可以」弄清楚如何正確地做到這一點。
如果有人會給我一個完整的例子來解決我的問題,這將非常感激。
您是將它連接到數據庫中的現有盒子,還是正在創建一個新盒子,但是已經在會話中設置了參數?會話本身存儲了什麼? –
@JasonRoman數據庫中已存在此框。會話保存箱數據(id,名稱)。編輯我的帖子以添加詳細信息...;) – Preciel