Yii:如何在视图页面上显示动态引导程序进度条 [英] Yii: How to show dynamic bootstrap progress bars on view page

查看:30
本文介绍了Yii:如何在视图页面上显示动态引导程序进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个yiibie.我的查看页面上有前 5 名非政府组织(每个月前 5 名非政府组织)以及同一页面上年底前 5 名的非政府组织.现在我想在每个非政府组织面前显示引导程序进度条.例如,如果 1 月是月份并且它向我显示该月的前 5 个非政府组织,我想在所有 5 个非政府组织的前面显示一个进度条,并且每个月我都想要它.年底也是一样.就像第一个非政府组织进度条将是 100%,第二个非政府组织将少于 100%,依此类推.请帮我做这件事,谢谢.这是我的控制器的代码,它具有视图文件功能

 公共函数 actionNgostats(){$this->layout='main';$myCurrYear = date("Y");$userYear=UserRateReviewNgo::model()->findAll(array('条件' =>'YEAR(date_created)=:year','参数' =>数组(':year'=>$myCurrYear),'select'='DISTINCT rate,ngo_id','order'='rate DESC','限制' =>5));$this->render('ngostats', array("userYear"=>$userYear));}

这是我的视图文件(ngostats)

 

<?phpfor($month = 1 ; $month <=date('m') ; $month++){$user=UserRateReviewNgo::model()->findAll(array('条件' =>'YEAR(date_created)=:year 和 MONTH(date_created)=:month','参数' =>数组(':year'=>2015, ':month'=>$month),'select'='DISTINCT rate,ngo_id','order'='rate DESC','限制' =>5));foreach($user as $show) {$model = Ngo::model()->findByAttributes(array('id'=>$show->ngo_id,));如果(isset($模型)){?><div><h4><?php echo $model->ngo_name?></h4></div><div class="progress"><div class="progress-bar progress-bar-striped active" role="progressbar"aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:40%">40%

<?php}}}?>

<h3>这是今年排名前 5 的 Ngo 的</h3><div><?php//年份foreach($userYear as $show) {$model = Ngo::model()->findByAttributes(array('id'=>$show->ngo_id,));如果(isset($模型)){?><div><h4><?php echo $model->ngo_name?></h4></div><div class="progress"><div class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar"aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:40%">40% 完成(成功)

<?php}}?>

解决方案

这个月我希望你能适应一年

一开始很简单,var $val 被设置为 100,这个值被分配到需要的地方,然后减少 20,循环重复

 

<?phpfor($month = 1 ; $month <=date('m') ; $month++){$dateObj = DateTime::createFromFormat('!m', $month);$monthName = $dateObj->format('F');回声<h3>".$monthName ."</h3>";$user=UserRateReviewNgo::model()->findAll(array('条件' =>'YEAR(date_created)=:year 和 MONTH(date_created)=:month','参数' =>数组(':year'=>2015, ':month'=>$month),'select'='DISTINCT rate,ngo_id','order'='rate DESC','限制' =>5));$val = 100;foreach($user as $show) {$model = Ngo::model()->findByAttributes(array('id'=>$show->ngo_id,));如果(isset($模型)){回声<div><h4>".$model->ngo_name ."</h4></div><div class='progress'><div class='progress-bar progress-bar-striped active' role='progressbar'aria-valuenow='" . $val ."' aria-valuemin='0' aria-valuemax='100' style='width: ". $val ."%;'>" . $val ."</div>

";$val = $val -20;}}}?>

I am a yiibie. I have top 5 ngo's on my view page(top 5 ngo's for each month) and also the top 5 ngo's at the end of the year on the same page. Now i want to show the bootstrap progress bar in front of every ngo. For example if January is the month and it is showing me top 5 ngo's of that month,I want to show a progress bar in front of all those 5 ngo's and I want it for every month. And same thing for the end of the year. Like the 1st ngo progress bar will be 100%, 2nd ngo will have less then 100% and so on. Please help me in doing this, thank you. This is my code for my controller which has the view file function

           public function actionNgostats()
{

    $this->layout='main';
    $myCurrYear = date("Y");
    $userYear=UserRateReviewNgo::model()->findAll(array(
        'condition' => 'YEAR(date_created)=:year',
        'params' => array(':year'=>$myCurrYear),
        'select'=>'DISTINCT rate,ngo_id',
        'order'=>'rate DESC',
        'limit' =>  5
     ));  
    $this->render('ngostats', array("userYear"=>$userYear));
}

and this is my view file(ngostats)

    <div>
    <?php
    for($month = 1 ; $month <=date('m') ; $month++) 
    {

     $user=UserRateReviewNgo::model()->findAll(array(
            'condition' => 'YEAR(date_created)=:year and MONTH(date_created)=:month',
            'params' => array(':year'=>2015, ':month'=>$month),
            'select'=>'DISTINCT rate,ngo_id',
        'order'=>'rate DESC',
        'limit' =>  5
         )); 
     foreach($user as $show) {
            $model = Ngo::model()->findByAttributes(array('id'=>$show->ngo_id,));
            if (isset($model)) {

?>
<div><h4><?php echo $model->ngo_name?></h4></div>
 <div class="progress">
  <div class="progress-bar progress-bar-striped active" role="progressbar"
  aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:40%">
    40%
  </div>
</div>

<?php
    }}}
?>
   </div> 


<h3>This is for the year's top 5 Ngo's</h3>
<div>   
    <?php // the for the year 
        foreach($userYear as $show) {
            $model = Ngo::model()->findByAttributes(array('id'=>$show->ngo_id,));
            if (isset($model)) {
            ?>
    <div><h4><?php echo $model->ngo_name?></h4></div>
 <div class="progress">
  <div class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar"
  aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:40%">
    40% Complete (success)
  </div>
</div>
    <?php
            }
        }
    ?>
</div>

解决方案

This is for the month i hope you are able to adapt for the year

Is simple at begin the var $val is set to 100 and this value is assigned where it is needed then is decremented by 20 and the cycle is repeated

 <div>
    <?php
    for($month = 1 ; $month <=date('m') ; $month++) 
    {

        $dateObj   = DateTime::createFromFormat('!m', $month);
        $monthName = $dateObj->format('F'); 
        echo "<h3> " . $monthName . "</h3>"; 

        $user=UserRateReviewNgo::model()->findAll(array(
            'condition' => 'YEAR(date_created)=:year and MONTH(date_created)=:month',
            'params' => array(':year'=>2015, ':month'=>$month),
            'select'=>'DISTINCT rate,ngo_id',
        'order'=>'rate DESC',
        'limit' =>  5
         )); 
        $val = 100;
        foreach($user as $show) {

            $model = Ngo::model()->findByAttributes(array('id'=>$show->ngo_id,));
            if (isset($model)) {
                echo "<div><h4>" . $model->ngo_name ."</h4></div>
                    <div class='progress'>
                    <div class='progress-bar progress-bar-striped active' role='progressbar'
                    aria-valuenow='" . $val ."' aria-valuemin='0' aria-valuemax='100' style='width: ". $val ."%;'>" .  $val .
                    "</div>
                    </div>";
                    $val = $val -20;
    }}}
    ?>
</div> 

这篇关于Yii:如何在视图页面上显示动态引导程序进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆