0
表單提交,驗證並將表單數據保存到服務器時,如何在Symfony2/3中更改csrf標記?在提交表單和驗證表單後更改CSRF令牌
// AppController.php
...
public function saveAction(Request $request) {
$event = new Data();
$form = $this->createForm(DataForm::class, $event);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$creator = $this->getDoctrine()
->getRepository('AppBundle:User')
->find($this->getUser()->getId());
$event->setCreator($creator);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($event);
$entityManager->flush();
<的東西在這裏改變CSRF令牌。有任何想法嗎? >
return $this->redirect($this->generateUrl('event_view', ['id' => $event->getId()]));
}
$message = ['text' => 'Wrong data to save', 'type' => 'danger'];
$this->get('session')->set('messages', [$message]);
return $this->redirect($this->generateUrl('event_create'));
}
...
OptionsResolverInterface已棄用。我使用了_'csrf_token_id'_類的OptionsResolver,而不是_'intention'_。謝謝。是工作 – chrisperk