Luke Luke - 1 year ago 231
PHP Question

CakePHP AJAX Layout

I'm working with a CakePHP application and jQuery Mobile. In the CakePHP application, RequestHandler is turned on, now, jQuery Mobile makes all of it's requests as ajax requests but requires a full page not just what is in my view but the full layout to.

I need requesthandler and I've tried to set a layout, force a render, turn off autolayout, nothing works, cake only returns the contents of my view.

I'd really love to know what's going on here.

Answer Source

If anyone is interested I found a solution to this, I found out that when you have RequestHandler on and make a Ajax request, it doesn't matter what you do, RequestHandler then decides that your layout is 'ajax' via call backs, this probably applies for all non-html request types, like json and text.

I had to set

$this->RequestHandler->enabled = false; 

It really needs to be set in beforeFilter() as well, latter in the call chain and it appears to not work.

So my code ended up as:

class AppController extends Controller {
  var $components = array('RequestHandler');
  function beforeFilter() {
    if ($this->RequestHandler->isMobile()) {
      $this->RequestHandler->enabled = false
      //set special mobile rules here
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download