Cakephp $layout 不会改变
所以情况是这样的: 我有我的default.ctp和我的ajax.ctp,其中我的ajax.ctp只是空白的$content_for_layout;
当我进行自动完成 ajax 调用时,我必须将布局更改为“ajax”。 所以我的控制器中有这个功能
function beforeFilter() {
if($this->RequestHandler->isAjax()) {
$this->layout = 'ajax';
}
}
但是当我查看自动完成的结果时,我在我的选项中得到了这个:
- DOCTYPE html PUBLIC“-//W3C // DTD XHTML 1.0 Transitional // EN”“http://www. w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
- html xmlns="http://www.w3.org/1999/xhtml">
基本上是我的默认布局。 所以我的猜测是布局没有改变
还有其他人遇到过这个问题吗?我是否忘记在控制器中添加某些内容?所有助手和组件都已就位。
So here is the situation:
I have my default.ctp and my ajax.ctp where my ajax.ctp is just the blank $content_for_layout;
When i'm doing an autocomplete ajax call I must change the layout to 'ajax' obviously.
So I have this function in my controller
function beforeFilter() {
if($this->RequestHandler->isAjax()) {
$this->layout = 'ajax';
}
}
However when i look at the results of my autocomplete I get this in my options:
- DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
- html xmlns="http://www.w3.org/1999/xhtml">
Which basicly is my default layout.
So my guess is that the layout didn't change
Anyone else encountered this problem? Did I forget to add something in my controller ? All the helpers and components are in place.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的脚本中没有太多可能出错的地方。之前过滤器好,设置视图模板也好。我唯一能想到的是你的ajax请求不知何故没有被识别。
RequestHandler::isAjax() 的代码非常简单:
因此我建议记录您的变量以查看它是否被识别为 ajax。我还听说有时缓存会搞砸。尝试 $this->disableCache();在检查它是否是ajax之前。
调试……是不是很有趣
There isn't that much that could go wrong in your script. Before filter is good and setting the view template is also. The only thing I can think of is that your ajax request somehow doesn't get recognized.
The code of RequestHandler::isAjax() is pretty simple:
So I suggest logging your vars to see if it's recognized as ajax. Also I heard sometimes the caching screws this up. Try $this->disableCache(); before checking if it's ajax.
Debugging ... isn't it fun