CakePHP AJAX布局 [英] CakePHP AJAX Layout

查看:139
本文介绍了CakePHP AJAX布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CakePHP应用程序和jQuery Mobile。在CakePHP应用程序中,RequestHandler已打开,现在,jQuery Mobile将所有请求作为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.

我需要requesthandler,我试图设置布局,强制渲染,关闭autolayout,没有什么工作,蛋糕只返回我的视图的内容。

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.

推荐答案

p>如果有人感兴趣,我发现一个解决方案,我发现,当你有RequestHandler,并提出一个Ajax请求,这并不重要你做什么,RequestHandler然后决定你的布局是ajax通过回调,这可能适用于所有非html请求类型,如json和文本。

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.

我必须设置

$this->RequestHandler->enabled = false; 

它真的需要在beforeFilter()中设置,后面的调用链不工作。

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

因此我的代码最终为:

class AppController extends Controller {
  var $components = array('RequestHandler');
  function beforeFilter() {
    if ($this->RequestHandler->isMobile()) {
      $this->RequestHandler->enabled = false
      //set special mobile rules here
    }
  }
}

这篇关于CakePHP AJAX布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆