【问题标题】:Remove first line while rendering data in symfony2在 symfony2 中渲染数据时删除第一行
【发布时间】:2015-06-02 09:03:49
【问题描述】:

我目前正在研究 symfony2 框架。我想要 twig 文件在一个文件中呈现的 html 数据。

我的代码:

    $myfile = fopen("somefile.html", "w");
    $data = $this->render("somefile.html.twig");
    fwrite($myfile, $data);

这工作正常,但除了 html 数据,我得到以下行
“HTTP/1.0 200 OK
缓存控制:无缓存
日期:       2015 年 6 月 2 日星期二 07:50:16 GMT"

作为一个凝视线,我想删除它们是否可以通过 symfony 或我使用正则表达式?

【问题讨论】:

    标签: php regex symfony twig


    【解决方案1】:

    尝试使用 renderView() 而不是 render()。

    $myfile = fopen("somefile.html", "w");
    $data = $this->renderView("somefile.html.twig");
    fwrite($myfile, $data);
    

    【讨论】:

      【解决方案2】:

      尝试添加->getContent()函数:

      $myfile = fopen("somefile.html", "w");
      $data = $this->render("somefile.html.twig");
      fwrite($myfile, $data->getContent());
      

      【讨论】:

        猜你喜欢
        • 2017-02-08
        • 2022-10-08
        • 1970-01-01
        • 2014-01-30
        • 2022-01-19
        • 1970-01-01
        • 2023-01-07
        • 2020-11-20
        • 1970-01-01
        相关资源
        最近更新 更多