tags:

views:

168

answers:

2

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
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
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
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