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

时间:2017-06-25 11:35:40

标签: php opencart

我搜索谷歌搜索上述问题的答案,但我没有找到任何答案。这是第3天,几乎是一晚的搜索。问题是我想将控制器功能的输出保存到文件中。更具体一点,我想保存输出:

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。

感谢。

1 个答案:

答案 0 :(得分:1)

如果它确实将内容输出到浏览器,您可以执行以下操作

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);
}
相关问题