普通网友 2011-06-17 12:27
浏览 33
已采纳

CakePHP AJAX布局

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.

  • 写回答

5条回答 默认 最新

  • duan0065626385 2011-06-18 07:59
    关注

    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
        }
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?