1
下一個就是我想要做的是:插入數據到數據庫
與FormBuilder
當表單提交的結果創建簡單的形式被保存到數據庫中的特定用戶(基於它的ID)
另外是來自控制器的代碼:
public function helloAction(Request $request, $id){//displaying individual results for particular user//
// find the username which was in the view//
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery('SELECT b FROM AcmeWebBundle:baza b WHERE b.id = :id')
->setParameter('id',$id);
$total = $query->getResult();
$baza = new baza();
$em = $this->getDoctrine()->getManager();
$em->persist($baza);
$form = $this->createFormBuilder($baza)
->add ('rating','choice',array('label'=>'TEST44','choices'=>array(
'1'=>'1',
'2'=>'2',
'3'=>'3',
'4'=>'4'
),
'expanded'=>true,
'multiple'=>false
))
->getForm();
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
// perform some action, such as saving the task to the database
$em->flush();
return new Response('<h1>THANKS FOR Your feedback !!!!</h1>');
}
}
return $this->render('AcmeWebBundle:Default:hello.html.twig',array('all'=>$total,'id'=>$id ,'form'=>$form->createView()));
}
}
但是這會在數據庫中創建新行,並且只爲評級列添加值。此外,id字段,用戶名等等是空的。
我想要做的是,額定值要添加爲列的評級,但爲特定的ID。
你是否對每個GET請求調用'$ em-> persist($ baza)'?你必須清理你的思想,重新組織你的想法。 – 2013-04-05 14:22:03