简体   繁体   English

如何在Symfony2中打开输出缓冲?

[英]How to turn on output buffering in Symfony2?

how do I turn on output_buffering for every request to my Sf2 app? 如何为对Sf2应用程序的每个请求打开output_buffering?

I need this to use the the FirePHPBundle , but I would prefer to have it application-wide. 我需要使用FirePHPBundle ,但是我希望在整个应用程序中使用它。

A good place to do this is in AppKernel's init method where the framework also registers various error handlers and debug flags: 一个合适的地方是在AppKernel的init方法中,该框架还注册各种错误处理程序和调试标志:

class AppKernel extends Kernel
{
...
public function init() 
{
    parent::init(); //do not forget to call this    

    if ($this->debug) {
        ob_start(); 
    }
}
}

This of course will call ob_start only in a development environment 当然,这只会在开发环境中调用ob_start

You need not to worry about calling ob_start here because as the php manual states: 您不必担心在这里调用ob_start ,因为php手册指出:

Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. 输出缓冲区是可堆叠的,也就是说,可以在另一个ob_start()活动时调用ob_start()。 Just make sure that you call ob_end_flush() the appropriate number of times. 只要确保您调用ob_end_flush()适当的次数即可。 If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order. 如果有多个输出回调函数处于活动状态,则会按嵌套顺序依次过滤每个输出函数的输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM