Symfony2着色表行取决于数据库值和配置参数 [英] Symfony2 coloring table rows depending on database value and config parameter

查看:197
本文介绍了Symfony2着色表行取决于数据库值和配置参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每一天都有美好的一天:
我是新的Symfony,这可能看起来很简单,但对我来说很复杂。
我有一个对象列表,实体内容叫worker,从中创建一个CollectionArray。该worker有一个DateInterval参数,我们称之为timeRamaining。然后我有来自app / config.yml的2配置参数,这些参数我可以称为Dangerous和veryDangerous(橙色和红色)...说如果剩余时间接近某些事件或在这种情况下退休。
现在在视图中,我有一个HTML表,显示工作人员列表取决于搜索参数,我一直在努力整个下午,使此列表显示红色或橙色行,以防此剩余时间为危险(橙色)或非常危险(红色)。
我不知道应该如何负责每一个任务...例如,确定行的颜色?是一个任务,我应该处理的工人或控制器或视图?工作者是看起来更容易的地方,因为控制器必须上下整个数组,但是工作者离视图太远,它是编程逻辑,然后在实体中我不能访问参数需要从app / config.yml。
这个问题可能看起来很蠢,但真的给我一个很难的时间...任何类似的例子,你可以告诉我,将受到好评和赞赏。
谢谢

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

推荐答案

在您的控制器中,您需要获取您的配置选项,并将其传递给您的视图,您的数据。

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,
        )
    );
}

在视图中,比较 $ data date to both danger&非常危险的阈值,并分配一个css类,它将允许您设置任何所需的样式。

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.

这篇关于Symfony2着色表行取决于数据库值和配置参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆