Created
August 5, 2016 10:11
-
-
Save kroatoanweb/f6c593493b2f5fdf08350bd6d3cb73da to your computer and use it in GitHub Desktop.
Detectar peticiones AJAX con Symfony
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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