Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Detectar peticiones AJAX con Symfony
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class DefaultController extends Controller
{
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
//Aquí calculariamos el contenido
//Si es una peticion ajax
if( $request->isXmlHttpRequest() ) {
return $this->render('index.json.twig');
}
return $this->render('index.html.twig');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.