CakePHP AJAX 布局 [英] CakePHP AJAX Layout

查看:28
本文介绍了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 并且我尝试设置布局、强制渲染、关闭自动布局,没有任何效果,cake 只返回我的视图内容.

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.

推荐答案

如果有人对此感兴趣,我找到了解决方案,我发现当您打开 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天全站免登陆