A
A
alex stephen2015-04-09 13:28:15
Yii
alex stephen, 2015-04-09 13:28:15

Yii2: dataProvider how to format output?

In general, a subject.
I created a controller and a view in gii. In actionIndex the following code (everything is standard):

$dataProvider = new ActiveDataProvider(.......
return $this->render('index', [
            'dataProvider' => $dataProvider,
        ]);

Among other things, dates (date) are displayed in the GridView table. Actually, how do I format them?
With a model it would be simple:
$model->birdthday= date("d.m.Y", strtotime($model->birthday));

What about dateProvider?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Grechushnikov, 2015-04-09
@berezuev

'columns' => [
    [
      'attribute' => 'name',
      'format' => 'html',
      'value' => function ($model) {
              return  Html::a(
                '<img src="'.Media::preview($model->image_id,100,100).'" class="pull-left img-thumbnail" />'
                . $model->name,
                ['/club/view', 'club_id'=>$model->id]
              );
            }
    ],
    [
      'attribute' => 'city_id',
      'format' => 'html',
      'value' => function ($model) {
              return  $model->city->name;
            }
    ],
    'members_count',
    [
      'attribute' => 'type',
      'format' => 'text',
      'value' => function ($model) {
              return  \app\models\Club::$types[ $model->type ];
            }
    ],
  ]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question