Re: HTML_Table and altrowattributes
| From: | Wes Rood | Date: | Thu, 20 May 2004 13:22:09 +0000 |
| Subject: | Re: HTML_Table and altrowattributes | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-12653@lists.php.net to get a copy of this message | ||
Thank you all for the comments. The wrapper class will solve my issue. I just threw it together and I'll paste it below so you can see what I am trying to do:
// usage:
// $table = new MyTable(array('Field1', 'Field2', 'etc' ));
// $table->addRow( array of data );
// .. etc// echo $table->toHtml(); class MyTable { var $table; function MyTable($headingArray) { //set table attributes $tableAttributes = array(); $tableAttributes['width'] = '100%'; $tableAttributes['cellspacing'] = '2'; $tableAttributes['cellpadding'] = '0'; $tableAttributes['border'] = '0'; //create the table class $this->table = new HTML_Table($tableAttributes); $this->table->addRow($headingArray, 'class=heading', 'TH'); } function addRow($row) { $this->table->addRow($row); } function toHtml() { $this->table->altRowAttributes(1, "class=odd", "class=even"); return $this->table->toHtml(); } } Bertrand Mansion wrote:
Wes Rood wrote:My simple solution will be to create a wrapper object around the html_table, exposing the methods of html_table I desire (namely addrow), and providing a tohtml method that will just call altrowattributes before calling toHtml on the "wrapped" html_table. I just wanted to bring up the idea of changing html_table - but I realize now after thinking it over more that it would probably be a big design change.Yes, and as Klaus said, it would also slow things down a little more. You can indeed use a wrapper, that would allow you to continue to use Html_Table even if it is updated later on. Bertrand Mansion Mamasam