2012-03-07 90 views
1

我使用這個類來創建HTML內容PHP HTML生成器類

http://code.google.com/p/php-class-html-generator/ 

我嘗試用這種方式來建立一個表,但是HTML結果是錯誤的...

$messalist = array(...); 

    $html = htmltag::createElement('table')->id($attr['id']); 

     foreach($messagelist as $message){ 
      $html->addElement('tr') 
      ->addElement('td')->setText($message['subject']) 
      ->addElement('td')->setText($message['from']) 
      ->addElement('td')->setText($message['date']) 
      ->addElement('td')->setText($message['size']); 
     } 

echo $html; 

怎麼辦它在正確的方式? 感謝

這是生成的html:

<table id="messagelist"> 
    <tr> 
    <td> 
    <td> 
    <td> 
    <td>1.91kB</td>23 Feb 11:56 AM</td>To: [email protected]</td>Re: helooo</td></tr> 
    <tr> 

    <td> 
    <td> 
    <td> 
    <td>1.67kB</td>27 Feb 6:56 AM</td>[email protected]</td>Re: Helloo</td></tr></table> 

,這就是我需要:

<table id="messagelist"> 
    <tr> 
    <td>1.91kB<td></td>23 Feb 11:56 AM</td><td>To: [email protected]</td><td>Re: helooo</td></tr> 
    <tr> 
    <td>1.67kB</td><td>27 Feb 6:56 AM</td><td>[email protected]</td><td>Re: Helloo</td></tr></table> 
+0

它生成了什麼HTML? – 2012-03-07 14:37:26

+0

剛剛發佈.. – Ste 2012-03-07 16:14:40

回答

3

嘗試:

foreach($messagelist as $message){ 
    $tr= $html->addElement('tr'); 
    $tr->addElement('td')->setText($message['subject']); 
    $tr->addElement('td')->setText($message['from']); 
    $tr->addElement('td')->setText($message['date']); 
    $tr->addElement('td')->setText($message['size']); 
} 
+0

嗨,剛剛編輯的問題 – Ste 2012-03-07 15:21:38

+0

@Ste所以你可以發佈你期望什麼,你有什麼?哪裏不對? – xdazz 2012-03-07 15:22:38

+0

編輯問題! – Ste 2012-03-07 16:12:33

0

不太熟悉這臺發電機,但你在最後一個 - > setText後面只包含了一個分號。那是合適的語法嗎?我以前見過這種速記,但通常需要您的第一個完整聲明:

$html->addElement('td')->setText($message['subject']) 
    ->addElement.... 
    ->addElement... 
    ->addElement....; 

可能值得一試。