代码之家  ›  专栏  ›  技术社区  ›  rxmnnxfpvg

cakephp XML(1.3)

  •  1
  • rxmnnxfpvg  · 技术社区  · 15 年前

    每当我输出一个XML文件时,我总是在顶部得到9行空白,有人知道问题是什么吗?我也会在结尾处得到一个时间戳,我不想这样:

    <!-- 0.35s -->
    

    错误如下:

    XML Parsing Error: XML or text declaration not at start of entity
    Location: http://example.com/controller/get
    Line Number 9, Column 1:<?xml version="1.0" encoding="UTF-8" ?>
    

    我放 $this->RequestHandler->setContent('xml','text/xml'); 在我的控制器里 beforeFilter() ,视图如下:

    <?php echo $xml->serialize($data); ?>
    

    虽然布局如下:

    <?php
        header("content-type: text/xml");
        echo $this->Xml->header();
        echo $content_for_layout;
    ?>
    

    有什么想法吗?谢谢。

    3 回复  |  直到 14 年前
        1
  •  1
  •   Community CDub    8 年前

    这9行空白可能是因为在项目中的某些PHP文件的末尾有带有空格的行。这在cakephp中已经让我多次陷入困境。

    有关删除所有PHP文件末尾空白行的简单方法,请参阅以下文章: Find all files with Blank or WS at BOF or EOF

        2
  •  2
  •   kaupov    15 年前

    您还可以在呈现之前将configure::write(“debug”,0);设置到控制器beforefilter()或任何其他方法/服务调用中,以消除时间戳。

        3
  •  1
  •   dhofstet    15 年前

    时间戳附加在 app/webroot/index.php ,这样您可以通过编辑此文件(在文件末尾找到相应的代码)来删除它。