渲染后继续执行 [英] Continue execution after render

查看:86
本文介绍了渲染后继续执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在渲染调用之后继续执行函数?我正在使用ajax,在将响应呈现给页面后能够清理服务器端会很好。当然,我可以再打电话给ajax,但我不愿意。

in cakephp is it possible to continue to execute a function after the render call? Im using ajax and it would be nice to be able to do some cleaning up server side after render the response to the page. Of course I could make another ajax call but I would prefer not to..

Tnx有任何想法。
Bjorsa

Tnx for any ideas. Bjorsa

推荐答案

来自CakePHP文档(重点是我的):

From the CakePHP docs (emphasis mine):


在每个请求的控制器操作结束时都会自动调用render()方法。此方法执行所有视图逻辑(使用您在set()方法中提供的数据),将视图放置在其布局内,并将其提供给最终用户

但是,如果您查看 AppController :: render 的源代码,它将把渲染的输出返回给调用方法。因此,从理论上讲,您可以执行以下操作:

But, if you look at the source for AppController::render, it returns the rendered output back to the calling method. So, theoretically, you could do something like:

$this->autoRender = false;
$outp = $this->render('myView');
// do cleanup stuff
echo $outp;
exit();

只要将 autoRender 设置为假,你应该很好。我没有亲自尝试过,但是看起来它应该可以按照您想要的方式工作。祝你好运!

As long as you have autoRender set to false, you should be good. I've not personally tried this, but it seems like it should work like you want. Good luck!

这篇关于渲染后继续执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆