Controller.php
public function actionIndex()
{
$searchModel = new PriplatekVazbaSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->query->distinct()->joinWith(['zpusoby_platby'])->andFilterWhere(['smazat' => '0']);
$dataProvider->sort->defaultOrder = ['id' => SORT_DESC];
$dataProvider->pagination = ['pageSize' => 20];
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
Model.php
//Level 2
public function getItem()
{
return $this->hasOne(Item::className(), ['id' => 'item_id']);
}
public function getItemname()
{
return $this->item ? $this->item->name : '- žadný model -';
}
//Level 3
public function getTypzbozi()
{
return $this->hasOne(TypZbozi::className(), ['id' => 'typ_zbozi_id'])->via('item');
}
public function getTypzboziname()
{
return $this->typzbozi ? $this->typzbozi->name : '- žadný typ zboži -';
}
index.php
'columns' => [
//['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'name',
'headerOptions' => ['style' => 'text-align: center;'], // title
'contentOptions' => ['style' => 'min-width: 20%;'], // table row
],
[
'attribute' => 'name_pl',
'contentOptions' => ['style' => 'min-width: 20%;'],
'format' => 'raw',
'value' => function ($model) {
if($model->name_pl)
{
return $model->name_pl;
}
else
{
return "";
}
},
],
[
'attribute' => 'vystaveno',
'value' => 'vystaveno',
'format' => ['date', 'php:d.m.Y'],
],
[
'attribute' => 'priplatek_model_options_id',
'filter' => Html::activeDropDownList($searchModel, 'priplatek_model_options_id', ArrayHelper::map(PriplatekModel::find()->joinWith('priplatek_model_options', true, 'INNER JOIN')->asArray()->all(), 'priplatek_model_options_id', 'priplatek_model_options.name'),['class'=>'form-control','prompt' => '']),
'value' => function ($model) {
if($model->priplatek_model_options_id)
{
$pmo = PriplatekModelOptions::findOne($model->priplatek_model_options_id);
return $pmo->name;
}
else
{
return "-";
}
},
'contentOptions' => ['style' => 'min-width: 20%;'],
],
[
'attribute' => 'itemname',
'contentOptions' => ['style' => 'min-width: 10%;'],
],
[
'attribute' => 'typzboziname',
'contentOptions' => ['style' => 'min-width: 10%;'],
],
[
'label' => 'Kopie',
'format' => 'raw',
'value' => function ($model) {
$url = $model->id;
if($url)
{
return '<a href="/seznam/copy/' . $url . '"><i class="fa fa-copy"></i></a>';
}
else
{
return '';
}
},
'contentOptions' => ['style' => 'min-width: 5%;'],
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update}',
'header' => 'Opravit',
'contentOptions' => ['style' => 'min-width: 5%;'],
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{delete}',
'header' => 'Smazat',
'contentOptions' => ['style' => 'min-width: 5%;'],
],
//['class' => 'yii\grid\ActionColumn'],
],