views:

113

answers:

2

Hi All,

I am using php with code igniter. I am designing a website with php. I have a requirement in brief described as below:

I have a view page with table in it. I load this view from many different controller .php files. Now i want one of the item in the table to appear with different colors when loaded from different .php controllers. Is this possible. Please give me a sample code to try out the same. Please let me know if you have any questions so that i can edit the same question and with your query.

I load my view by using the below code

$this->load->view('header');

Thanks in advance for all you help provided.

+2  A: 

you can do this

Controller

$data["color"] = "red";
$this->load->view('header',$data); //pass the parameters

for more details see Adding dynamic data

View

<table>
  ...
  <tr>
    <td class="<?php echo $color;?>">
      Data in cell that is colored
    </td>
  </tr>
  ...
</table>

CSS

.red { background: #f00; color: #fff;}

Also if you want to change the colors from the stylesheet try passing the controller name and change the colors respectively in the stylesheet. If you need more help update the question and I will try to help.

Virat Kadaru
+1  A: 

A cool way to do it is to dynamically set load a css file when you load your table.

So logically it would look something like this from the html page:

<?php
$controller = getController(?);
?>

<html>
<head>
<link rel="stylesheet" type="text/css" href=<?php echo "\"css/" . $controller->getCSS() . ".css\""; ?> />
</head>
<body>
...
<?php echo $controller->getTable(); ?>
...
</body>
</html>

The table would have the same css class no matter what controller it comes from.

Justin Giboney