Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
227 views
in Technique[技术] by (71.8m points)

php - Symfony2 coloring table rows depending on database value and config parameter

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...