I have a list of ads for my website. I would like to be able to visually tell if an ad is still active based on its row color in the index.ctp list. I have a form that controls each entry. In the form there is a $end_date. The color will based on that date. Not really knowing what I am doing I figured I'll need a sort of function in my AdsController to perform the logic. Please let me know if I'm on the right track.
The issue now is that no color change is showing up. Here is the code:
public function getStatusColor($status_color) {
$this->loadModel('Advertisements');
$date = $this->Advertisements->get($end_date);
$now = new DateTime();
if($date < $now) {
echo '#ff0000' ;
} else {
echo '#00ff00' ;
}
}
In my index.ctp, this is just a portion of the list code just so you can see how I might splice the color into the table
foreach($advertisements as $advertisement) {
echo '<tr style="background-color: <?php echo $status_color; ?>;">';
echo '<td>'.$advertisement->id.'</td>';
echo '<td>'.$advertisement->title.'</td>';