尝试使用Heredoc尝试创建具有双foreach的表行时出现tcpdf错误

时间:2019-10-02 07:33:38

标签: php tcpdf heredoc

我正在尝试使用Heredoc方法动态添加行和列,但是当我将每个行和列添加到另一个时,会出现错误:

Notice: Undefined index: startcolumn in C:\xampp\htdocs\vendor\tecnickcom\tcpdf\tcpdf.php on line 19537
Notice: Undefined index: startx in C:\xampp\htdocs\vendor\tecnickcom\tcpdf\tcpdf.php on line 19538
Notice: Undefined index: startpage in C:\xampp\htdocs\vendor\tecnickcom\tcpdf\tcpdf.php on line 19541
Notice: Undefined index: startpage in C:\xampp\htdocs\vendor\tecnickcom\tcpdf\tcpdf.php on line 19544
Notice: Undefined index: in C:\xampp\htdocs\vendor\tecnickcom\tcpdf\tcpdf.php on line 19544
Notice: Undefined index: startpage in C:\xampp\htdocs\vendor\tecnickcom\tcpdf\tcpdf.php on line 19545
Notice: Undefined index: in C:\xampp\htdocs\vendor\tecnickcom\tcpdf\tcpdf.php on line 19545
Notice: Undefined index: startpage in C:\xampp\htdocs\vendor\tecnickcom\tcpdf\tcpdf.php on line 19577
Notice: Undefined index: startx in C:\xampp\htdocs\vendor\tecnickcom\tcpdf\tcpdf.php on line 19797
TCPDF ERROR: Some data has already been output, can't send PDF file

这是代码:


    function Table($header, $data)
    {
        $this->SetFont('helvetica', 'B', 6);
        $tbl = <<<EOD
        <table border="1" cellpadding="1" cellspacing="0" nobr="true">
        <tr>
        EOD;
        foreach($header as $col) {
            $tbl.=<<<EOD
                    <th>{$col}</th>
            EOD;
             }
        $tbl.=<<<EOD
        </tr>
        EOD;
        foreach ($data as $row) {
            //When adding this second row definition this causes errors
            $tbl.= <<<EOD
            <tr>
            EOD;
            foreach ($row as $col) {
            $tbl.= <<<EOD
                    <td>{$col}</td>
            EOD;
            }
            $tbl.= <<<EOD
            </tr>
            EOD;
             }
        $tbl.=<<<EOD
        </table>
        EOD;
        $this->writeHTML($tbl, true, false, false, false, '');
    }

此特定错误似乎来自添加第二个表行标记。当我没有第二个表行定义时,一切正常,并且我确定我关闭了所有标记/格式正确,所以对于我一生,我无法弄清楚为什么它不起作用添加:

    $tbl.= <<<EOD
      <tr>
    EOD;
    //And the closing tr tag

对于内部的forloop,它会导致我出错,但我不知道为什么。 我知道该函数比较杂乱,但是我正在使用自己拥有的函数。



编辑和工作:在打印出一些值来代替标签后,我注意到它也正在遍历一个空值,因此我从此删除并解决了我的问题。

0 个答案:

没有答案