Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@calcio
Created March 4, 2017 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calcio/6e6ac6943e88937f1d07afe678153c6b to your computer and use it in GitHub Desktop.
Save calcio/6e6ac6943e88937f1d07afe678153c6b to your computer and use it in GitHub Desktop.
Example of GridView and DetailView in Yii 2
<?= DetailView::widget([
'model' => $model,
'template' => '<tr><th class="col-sm-2">{label}</th> <td>{value}</td></tr>',
'attributes' => [
'full_name',
'date_born:date',
'address',
[
'attribute' => 'sex',
'value' => ($model->sex === 1) ? 'Male' : 'Female',
],
],
]) ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
[
'class' => 'yii\grid\SerialColumn',
'headerOptions' => ['class' => 'col-sm-1 text-center'],
'contentOptions' => ['class' => 'text-center'],
],
'full_name',
'address',
[
'class' => 'yii\grid\ActionColumn',
'headerOptions' => ['class' => 'col-sm-1 text-center'],
'contentOptions' => ['class' => 'text-center'],
],
],
]); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment