Skip to content

Instantly share code, notes, and snippets.

@kroatoanweb
Created August 5, 2016 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kroatoanweb/f6c593493b2f5fdf08350bd6d3cb73da to your computer and use it in GitHub Desktop.
Save kroatoanweb/f6c593493b2f5fdf08350bd6d3cb73da to your computer and use it in GitHub Desktop.
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