2013-03-03 115 views
2

這是我在PdfHtml類代碼:DOMPDF,給我帶來了錯誤

public function createTable($result){ 

    $html = "<html> 
        <body> 
         <table> 
          <th> 
           <td>Descripción</td> 
           <td>Artículo</td> 
           <td>Precio</td> 
          </th> 
         "; 
    while($row = mysql_fetch_array($result)){ 
     $html .= "<tr>"; 
     $html .= "<td>".$row["producto"]."</td>"; 
     $html .= "<td>".$row["idProducto"]."</td>"; 
     $html .= "<td>".$row["precio"]."</td>"; 
     $html .= "</tr>"; 
    } 

    $html .= "</table> 
       </body> 
        </html>"; 

    return $html; 
} 
</i> 

我用下面的執行:

$pdfHtml = new PdfHTML(); 
$result = $pdfHtml->getProductosPorMarca($idMarca); 
$html = $pdfHtml->createTable($result); 

$dompdf = new DOMPDF(); 
$dompdf->load_html($html); 
$dompdf->render(); 
$dompdf->output(); 

而拋出這個:

Catchable fatal error: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, null given, called in /opt/lampp/htdocs/ONLINE/dompdf0.6/include/table_frame_decorator.cls.php on line 304 and defined in /opt/lampp/htdocs/ONLINE/dompdf0.6/include/frame.cls.php on line 726 

請幫助我,我不發現哪裏是我的錯誤!謝謝!!

回答

6

您的HTML是問題的根源。你已經在TH元素內嵌入了一堆TD元素,但這是無效的。容器應該仍然是TR元素;那麼單個細胞就會成爲TH元素。如果你想要一個在頁面上重複的表頭,你可以在THEAD元素和TBODY元素中的表體中嵌套標題行。

+0

Ichange此HTML代碼,並給我帶來了這樣:致命錯誤:調用未定義方法399行中的/opt/lampp/htdocs/ONLINE/dompdf0.6/include/cellmap.cls.php中的DOMText :: getAttribute()。 您是否有示例?謝謝 – user1977204 2013-03-03 19:30:45

+0

更新後的代碼示例將有助於弄清楚您的代碼正在發生什麼。您可能還想嘗試驗證您的代碼生成的HTML:http://validator.w3.org – BrianS 2013-03-04 04:48:57

0

基本<表>元素:

$html = "<html> 
        <body> 
         <table> 
          <tr> 
           <th>Descripción</th> 
           <th>Artículo</th> 
           <th>Precio</th> 
          </tr> 
         "; 
0

使用單引號(' '),像這樣:

public function createTable($result){ 
    $html = '<html> 
       <body> 
        <table> 
         <th> 
          <td>Descripción</td> 
          <td>Artículo</td> 
          <td>Precio</td> 
         </th>'; 


    while($row = mysql_fetch_array($result)){ 
    $html .= "<tr>"; 
    $html .= "<td>".$row["producto"]."</td>"; 
    $html .= "<td>".$row["idProducto"]."</td>"; 
    $html .= "<td>".$row["precio"]."</td>"; 
    $html .= "</tr>'; 
    } 

    $html .= '</table> 
      </body> 
      </html>'; 

    return $html; 
} 
+0

請編輯您的代碼塊以獲得更好的可讀性。 – 2015-07-29 17:38:05