CakePHP AJAX 布局

CakePHP AJAX Layout(CakePHP AJAX 布局)
本文介绍了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 布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)