Hi,

Symfony2 offers you a method in the request object called:
"isXmlHttpRequest()".

See Symfony\Component\HttpFoundation\Request.php
    /**
     * Returns true if the request is a XMLHttpRequest.
     *
     * It works if your JavaScript library set an X-Requested-With
HTTP header.
     * It is known to work with Prototype, Mootools, jQuery.
     *
     * @return Boolean true if the request is an XMLHttpRequest, false
otherwise
     */
    public function isXmlHttpRequest()
    {
        return 'XMLHttpRequest' == $this->headers->get('X-Requested-
With');
    }

You just have to get the request object in the controller:
$request = $this->get('request');
$request->isXmlHttpRequest()

But I have never used it before...

greets,
Oli


On Feb 27, 8:48 pm, Christophe Beyer <cbe...@cap-tic.fr> wrote:
> Hello,
>
> I want to display a template in two modes : the "normal" mode, embedded
> in the main layout, and an ajax mode; without duplicate my template of
> course.
>
> 1. In my controller, how can I check if the requested url is an ajax
> request (without adding any parameter) ?
>
> 2. In the Twig file, I tried to make this :
> {% if ajax %}{% extends "MyBundle::layout.twig.html" %}{% endif %}
> but it doesn't work.
>
> Any suggestion ?
>
> Thanks !
>
> --
> Christophe

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to