如何从模型中在Yii2 GridView中打印第一提醒,第二提醒?

时间:2018-07-31 11:15:52

标签: php mysql gridview yii2

这是我的查看页面view.php

<div class="dataTables_wrapper form-inline dt-bootstrap">
    <?= GridView::widget([
         'dataProvider' => $dataProvider1,
         'columns' => [
              ['class' => 'yii\grid\SerialColumn'],            
              [
                  'label' =>'Date',
                  'value' => 'date',
              ],
              [
                  'label' =>'Reminder',
                  'value' => function($model){
                       return Yii::$app->session->get('').' '.$model['type'].' '.'reminder';
                  }  
              ],
              [
                  'label' =>'To',
                  'value' => 'recipients',
              ],                    
         ]
    ]); ?>
</div>

这是控制者

$dataProvider1 = new ActiveDataProvider([
    'query' => DomainReminders::find()
                 ->where(['domain_id'=>$model['id']])
]);
$totalCount = $dataProvider1->getTotalCount();

return $this->renderAjax('view', [
   'totalCount' => $totalCount, 
   'dataProvider' => $dataProvider, 
   'dataProvider1' => $dataProvider1, 
   true, 
   true
);

这是列名称为'type'的数据库,我希望在网格视图中像第一个提醒,第二个提醒,第三个提醒一样打印

enter image description here

现在这是我要打印的输出,如第一,第二提醒

enter image description here

1 个答案:

答案 0 :(得分:3)

您可以为此使用Inflector::ordinalize()

[
    'label' => 'Reminder',
    'value' => function ($model) {
        return Inflector::ordinalize($model['type']) . ' reminder';
    },
],