How can I get a different css class for each table header?
+1
A:
I'm guessing you're looking for this?
echo $html->tableHeaders(
array(
array('Title for first cell', array('class' => 'class for first cell')),
array('Title for second cell', array('id' => 'id for second cell')),
array('Title for third cell', array('class' => 'thirdClass', 'id' => 'thirdId'))
)
);
deceze
2009-12-12 03:47:21
I'm after a similar thing, but all this does it turn my table header text into "Array". Anyone got a working answer for this yet? (using cakephp 1.3)
Hippyjim
2010-10-18 11:57:46
A:
I don't really see the point of using the HTML helper for such task. It's just faster and more natural to simply write your own HTML table.
That being said, you could use a simple counter for your th
<?php $k = 0; ?>
<tr>
<th class="classeOne classTwo<?php if($k++ % 2 == 0) echo ' alt'; ?>"> foo </th>
...
</tr>
If you're looking to have a totally different class for every header, you could do :
<?php
$thClasses = array(
'classOne',
'classTwo',
'classThree');
$k = 0;
?>
<tr>
<th class="<?php echo thClasses[$k++]; ?>"> foo </th>
...
</tr>
Jimmy
2009-12-12 17:03:47
It makes sense if you're generating the table in a Helper. Rather than working with string concatenation or even breaking out of PHP you just write arrays. In a normal template it's borderline… :)
deceze
2009-12-13 00:09:59