Amy
Amy

Reputation: 1

Css classes in CakePHP?

How can I get a different css class for each table header?

Upvotes: 0

Views: 584

Answers (2)

Jimmy
Jimmy

Reputation: 978

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>

Upvotes: 0

deceze
deceze

Reputation: 522625

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'))
    )
);

Upvotes: 1

Related Questions