我想執行我的控制器動作,但之後我渲染視圖給用戶,這裏是我的控制器操作的Symfony2控制器發送答案後執行操作
public function addAction(Request $request)
{
$this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Vous n\'avez pas les droits pour accéder à cette page');
$preconisation = new Preconisation();
$form = $this->createForm(new PreconisationType($preconisation), $preconisation);
if($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$rapport = $em->getRepository('DataBaseBundle:rapport')->findByIdRapport($preconisation->getRapport()->getIdRapport());
$rapport[0]->incPreco($preconisation->getRapport()->getIdRapport());
$em->persist($preconisation);
$em->persist($rapport[0]);
$em->flush();
return $this->redirect($this->generateUrl('data_base_preconisation_index'));
}
}
return $this->render('DataBaseBundle:Preconisation:add.thml.twig', array('form' => $form->createView(),'menu' => 1,
'leftMenu' => 1,));
}
所以
我想用戶後才能執行此已經收到了他的答案,以避免充電時間長
$rapport = $em->getRepository('DataBaseBundle:rapport')->findByIdRapport($preconisation->getRapport()->getIdRapport());
$rapport[0]->incPreco($preconisation->getRapport()->getIdRapport());
$em->persist($rapport[0]);
我看到了,我可以使用監聽器和調度員,但我真的不unders他的結構或它的工作原理。但我也看到了httpKernel與終止事件。不幸的是我沒有答案。我不知道哪一個是最好的...
有什麼建議嗎?
那你知道在哪裏可以找到使用監聽器的symfony的2.8應用程序的一個例子遙遠的PHP腳本?因爲在食譜上,理解它的結構並不容易。 – T3ddy