对于控制器中不需要视图的操作,我将禁用布局和模板,如下所示:
$this->autoRender = false;
一切都很好。然而,在同一操作中,我会回显“通过”或“失败”来表明我对结果的看法。问题是一堆文本也被回显:(我的“失败”或“通过”在最后)
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
</body>
</html>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
<head> ....
这被重复了 8 到 9 次。
我怎样才能摆脱它,只回显我的“通过”或“失败”?
你能帮我吗?
我试过了
$this->layout = false; and
$this->render(false);
太感谢了。
更新:**
首先,我将在这里粘贴来自 cakeapi 的片段http://api.cakephp.org/class/controller http://api.cakephp.org/class/controller关于 autoRender 的工作原理:
自动渲染布尔值
设置为 true 以自动渲染视图after动作逻辑。
So this:
$this->autoRender = false ;
通常会在操作逻辑完成后关闭渲染视图。这就是为什么你会从你的行动逻辑中得到回应。您可以从代码中删除回显以防止显示它们,或者尝试此模式,
如果出现问题:
$this->Session->setFlash('Error');
$this->redirect(array('action' => 'your_error_page'));
这会将您移至错误页面,其中错误字符串为 Flash 文本,或者一切正常时:
$this->Session->setFlash('Its fine dude!');
$this->redirect(array('action' => 'your_ok_page'));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)