Zend framework 在Zend_视图中禁用输出缓冲

Zend framework 在Zend_视图中禁用输出缓冲,zend-framework,zend-view,Zend Framework,Zend View,我早就料到了 class Default_Plugin_Test extends Zend_Controller_Plugin_Abstract { public function preDispatch($request) { Zend_Controller_Front::getInstance()->setParam('disableOutputBuffering', true); } } 也会禁用与操作关联的视图中的缓冲,但它不会 即使在视图中禁用输出缓冲似乎

我早就料到了

class Default_Plugin_Test extends Zend_Controller_Plugin_Abstract { public function preDispatch($request) { Zend_Controller_Front::getInstance()->setParam('disableOutputBuffering', true); } } 也会禁用与操作关联的视图中的缓冲,但它不会

即使在视图中禁用输出缓冲似乎也是不可能的,因为它是硬编码的:

abstract class Zend_View_Abstract implements Zend_View_Interface { /** * Processes a view script and returns the output. * * @param string $name The script name to process. * @return string The script output. */ public function render($name) { // find the script file name using the parent private method $this->_file = $this->_script($name); unset($name); // remove $name from local scope ob_start(); $this->_run($this->_file); return $this->_filter(ob_get_clean()); // filter output } } 有没有人有过类似的经历,或者对此有解决方案

有一件事,不要这样做

视图负责显示传递给它的内容。控制器/操作接收请求,确定需要执行的操作、写入数据库、从数据库获取等。然后将输出分配给视图,视图显示输出

如果您开始在视图之外显示页面的某些部分,那么您就要打破MVC模型,这正是您应该使用Zend Framework的原因

你的实际问题是什么

编辑:

不要像这样运行CRON作业。将它们作为独立脚本运行,并实例化Zend框架和库以供CRON使用。cron不需要MVC模式来运行、使用电子邮件或其他输出。您期望CRON的输出,并将该输出用作确定CRON是否成功的一种有意义的方式,这一事实并不是使用CRON的正确方式。您应该记录输出,以便以后查看或通过电子邮件发送

通过这样做,您可以实例化ZF而不是分派它

 $application->bootstrap();
而不是这个

 $application->bootstrap()->run();
有一件事,不要这样做

视图负责显示传递给它的内容。控制器/操作接收请求,确定需要执行的操作、写入数据库、从数据库获取等。然后将输出分配给视图,视图显示输出

如果您开始在视图之外显示页面的某些部分,那么您就要打破MVC模型,这正是您应该使用Zend Framework的原因

你的实际问题是什么

编辑:

不要像这样运行CRON作业。将它们作为独立脚本运行,并实例化Zend框架和库以供CRON使用。cron不需要MVC模式来运行、使用电子邮件或其他输出。您期望CRON的输出,并将该输出用作确定CRON是否成功的一种有意义的方式,这一事实并不是使用CRON的正确方式。您应该记录输出,以便以后查看或通过电子邮件发送

通过这样做,您可以实例化ZF而不是分派它

 $application->bootstrap();
而不是这个

 $application->bootstrap()->run();

这适用于ZF的第1版

根据,在引导调用之前和Zend_应用程序实例化之后,必须在public/index.php中禁用输出缓冲:

我用这样的方式:

$application = Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);

if(APPLICATION_ENV !== 'production') {
    $frontController = Zend_Controller_Front::getInstance();
    $frontController->setParam('disableOutputBuffering', true);
}

$application->bootstrap()->run();

请注意,在application.ini中设置此选项无效。

这适用于ZF的版本1

根据,在引导调用之前和Zend_应用程序实例化之后,必须在public/index.php中禁用输出缓冲:

我用这样的方式:

$application = Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);

if(APPLICATION_ENV !== 'production') {
    $frontController = Zend_Controller_Front::getInstance();
    $frontController->setParam('disableOutputBuffering', true);
}

$application->bootstrap()->run();

请注意,在application.ini中设置此选项无效。

我是否可以知道您为什么需要禁用输出缓冲?我是否可以知道您为什么需要禁用输出缓冲?我完全同意您的看法。问题是Zend_视图正在缓冲输出,在操作完成之前,您无法看到任何输出。但是,我们有cron作业,它们可能需要很长时间才能运行,我们希望“实时”查看输出,而不需要缓冲。Zend_Controller_Front::getInstance->setParam'disableOutputBuffering',true;我应该这样做,但它没有按预期工作。我100%同意你。问题是Zend_视图正在缓冲输出,在操作完成之前,您无法看到任何输出。但是,我们有cron作业,它们可能需要很长时间才能运行,我们希望“实时”查看输出,而不需要缓冲。Zend_Controller_Front::getInstance->setParam'disableOutputBuffering',true;应该这样做,但它没有按预期工作。