渲染后继续执行 [英] Continue execution after render
问题描述
是否可以在渲染调用之后继续执行函数?我正在使用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屋!