dtxs9017 2013-10-15 05:47
浏览 45
已采纳

Symfony2着色表行取决于数据库值和配置参数

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

  • 写回答

1条回答 默认 最新

  • douduan5086 2013-10-15 08:23
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 arduino控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题