CakePHP AJAX Layout(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 布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CakePHP AJAX 布局
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Laravel 仓库 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
