如何将控制器函数的输出保存到文件中?

How can I save the output of a controller function to a file?

我在 Google 中搜索了上述问题的答案,但没有找到。这是第三天,几乎是一夜的寻找。问题是我想将控制器函数的输出保存到文件中。更具体地说,我想保存以下输出:

public function invoice() {
  //some codes are in here
  $this->template = 'sale/order_invoice.tpl';
  $this->response->setOutput($this->render());
}

据我了解,$this->render() 渲染上面指定的模板,setOutput() 将渲染模板的输出发送到浏览器。我正在使用 Opencart 1.5.6.

谢谢。

如果它确实将内容输出到浏览器,您可以像下面那样做

public function invoice() {
    $this->template = 'sale/order_invoice.tpl';
    $out = ob_start();    
    $this->response->setOutput($this->render());
    $out = ob_get_clean();
    file_put_contents('YOUR_FILE_LOCATION', $out);
}