tags:

views:

349

answers:

3

I'm doing some experimenting with AJAX in CakePHP and it seems to work except that the view that gets returned includes the default template. How can I get rid of that (or even just specify a different empty template for a view)?

+4  A: 
function ajaxFunction() {
    //do stuff
    $this->layout= 'ajax';
}

Ajax is an included blank layout to prevent extra markup being added, exactly what you want.

http://book.cakephp.org/view/96/Layouts

seanmonstar
That is exactly it! Thanks! That layout still includes debug info but now that I look it's just the SQL and not the controller dump which is exactly what I would need . . very cool.
tooshel
+4  A: 

Try using RequestHandler component. This will be handled automatically for you. Then, you can do something like this in your AppController::beforeFilter()

if($this->RequestHandler->isAjax()) {
    Configure::write('debug',0);
}
jmcneese
+1  A: 

You will also need to turn off debug output otherwise cake will squirt out all the debug info you usually see at the bottom of the page:

function ajaxFunction() {
    //do stuff
    Configure::write('debug', 0);
    $this->layout= 'ajax';
}
RichardAtHome