I am a newbie to Symfony 2. I am using Symfony 2.3.
I am using yml files for my routes. I want a certain route to be restricted for Ajax call only. How can I achieve that? I have found one similar question but the solution it suggested is for Symfony 2.4
So please help me how can I achieve it.
Currently I have written conditional code in my controller ajax action something like below, but I do not know how to handle if the call to that route is not through Ajax.
if ($request->isXmlHttpRequest()) {
// Some operations
// Prepare the data array based on the Ajax request.
}
return $this->render('AcmeBundle:Ajax:index.html.twig', array('data' => $data));
I want that this route can be accessed only with Ajax else it should throw some exception like invalid route or redirect to some other page.
Thanks in advance.