CakePHP AJAX Layout

后端 未结 5 1051
清歌不尽
清歌不尽 2021-01-15 14:05

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 re

5条回答
  •  时光说笑
    2021-01-15 14:35

    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
        }
      }
    }
    

提交回复
热议问题