/** * @Route("/vote/{id}/{dir}/{token}", * name="fortune_vote", * requirements={ * "id"="\d+", * "dir"="up|down", * } * ) */ public function voteAction(Request $request, Fortune $fortune, $dir, $token) { if (!$this->isCsrfTokenValid('', $token)) { throw $this->createNotFoundException('Invalid CSRF.'); } $fortune->vote($dir); $this->getDoctrine()->getManager()->flush(); if ($request->isXmlHttpRequest()) { return new JsonResponse(array('votes' => $fortune->getVotes())); } return $this->redirect($this->generateUrl('fortune_list')); }