2011-03-17 56 views
1

嗨我想在使用Zend Framework的页面生成结束时调用一个方法。这个怎么做?Zend Framework - 在构建页面的末尾调用一些东西

我正在使用Doctrine2 + ZF。 EntityManager有一个flush方法,它应该在通常情况下只在页面生成结束时被调用。 Zend Framework中是否有钩子或析构函数模拟? 2

+0

好年底执行最近这样的:http://stackoverflow.com/questions/2253170/zend-framework-last-code-to-execute-布局前呈现给我的帮助比这里的答案更多。我不得不覆盖postDispatch(),但也许我会改变这一点,以便能够在$ em-> flush()出现错误时显示错误消息。 – 2011-03-17 23:58:38

回答

4

使用controller plugin。我假设dispatchLoopShutdown是你需要的。

+0

是否正在调用推荐的父级方法? \t protected function dispatchLoopShutdown(){ \t \t parent :: dispatchLoopShutdown(); \t \t $ this - > _ em-> flush(); \t} – 2011-03-17 22:59:03

0

为什么只是不使用自己的功能?

呼叫register_shutdown_function();和传递功能将在脚本

+0

我不认为这是好的做法。 – Xerkus 2011-03-17 23:31:12