开发者

Disable output buffering in Zend_View

I was expecting that

class Default_Plugin_Test  extends Zend_Controller_Plugin_Abstract
{
  public function preDispatch($request)
  {
        Zend_Controller_Front::getInstance()->setParam('disableOutputBuffering', true);
  }
}

would also disable the buffering in the view associated with the action, but it doesn't.

Even it seems not possible to disable the output buffering in the view as it is hard coded:


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 sc开发者_开发知识库ript 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
    }
}

Did anyone had similar experience, or has a solution to this ?


One thing, do not do this.

The view is responsible for displaying what ever is passed to it. The request is received by the controller/action and they determine what needs to be done, write to database, get from database, etc. They then assign output to the view and the view displays it.

If you start displaying parts of your page outside of the view then your breaking the MVC model, the very reason you should be using Zend Framework.

What is your actual problem?

Edit:

Do not run CRON jobs like this. Run them as standalone scripts and instantiate your Zend Framework and libraries for the CRON to use. CRONs do not need a MVC pattern in order to run, use email or something else for the output. The fact that your expecting the output from a CRON and using that output as a meaningful way of determining if the CRON was successful for not is not really the right way to use a CRON. You should log the output for reviewing later or email it.

You can instantiate ZF and not dispatch it by doing this

 $application->bootstrap();

Instead of this

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


This applies to version 1 of ZF.

As per this page, you must disable output buffering in public/index.php (before the bootstrap call and after the Zend_Application instantiation):

I use something like this:

$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();

Note that setting this option in the application.ini does not work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜