我目前正在symfony2框架上工作。我想要的html数据,树枝文件呈现在一个文件。
我代码: $myfile = fopen("somefile.html", "w");
$data = $this->render("somefile.html.twig");
fwrite($myfile, $data);
这工作得很好,但除了html数据,我得到以下行
"HTTP/1.0 200 OK
cache - control: no - cache
日期:,,,,,,
作为起始行,我想删除它们是可能通过symfony还是我使用正则表达式?
尝试使用renderView()代替render()。
$myfile = fopen("somefile.html", "w");
$data = $this->renderView("somefile.html.twig");
fwrite($myfile, $data);
尝试添加->getContent()函数:
$myfile = fopen("somefile.html", "w");
$data = $this->render("somefile.html.twig");
fwrite($myfile, $data->getContent());