Good day every one: I am new Symfony and this might seem simple to someone but to me is complex. I have a list of objects an entity content called worker from where I create a CollectionArray. That worker has a parameter that is a DateInterval let's call it timeRamaining. Then I have 2 config parameter that come from app/config.yml, those parameter I can call them Dangerrous and veryDangerous (Orange and RED)... to say if the time remaining is close to some event or not, in this case Retirement. Now In the view I have an HTML table that shows the workers List depending on search parameters, I have been struggling the whole afternoon to make this list to show red or orange rows in case this remaining time is Dangerous (orange) or veryDangerous (Red). I do not know how is supposed to be responsible of every task... for instance, determining the color of the row? Is a task that I should handle to the worker or the controller or the view? the worker is the place where it seems easier because the controller has to go up and down the whole array, but the worker is too far from the view, it's programming logic and then in the entity I do not have access to the parameters that I need from the app/config.yml. This question might seem silly, but is really giving me a hard time... any similar example that you can show me will be well received and appreciated. Thank you
Asked
Active
Viewed 163 times
1 Answers
0
In your controller you need to fetch your configuration options and pass it to your view as well as your data.
public function tableAction() {
$dangerousThreshold = $this->container->getParameter('dangerous_threshold');
$veryDangerousThreshold = $this->container->getParameter('very_dangerous_threshold');
// If required transform your threshold in a comparable value, eg. a date.
$data = $this->container->get('your_repository')->findAll();
return $this->render(
'YourBundle:Dashboard:table.html.twig',
array(
'data' => $data,
'dangerous_threshold' => $dangerousThreshold,
'very_dangerous_threshold' => $veryDangerousThreshold,
)
);
}
And in the view, compare the $data
date to both dangerous & very dangerous threshold and assign a css class which will allow you to set any style you want.

Boris Guéry
- 47,316
- 8
- 52
- 87
-
Thank you, it sounds pretty good and straight forward. I'll try and let you know... – Abel Oct 16 '13 at 09:14