feat: display images in list
This commit is contained in:
parent
1fc412ba57
commit
f9d29e15f5
|
@ -24,7 +24,7 @@ class ParameterSearch extends Parameter
|
|||
|
||||
public function search($params): ActiveDataProvider
|
||||
{
|
||||
$query = Parameter::find();
|
||||
$query = Parameter::find()->with(['icon', 'iconGray']);
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
use app\models\Parameter;
|
||||
use yii\helpers\Html;
|
||||
use yii\bootstrap5\ActiveForm;
|
||||
use yii\grid\GridView;
|
||||
|
@ -7,6 +8,7 @@ use yii\grid\GridView;
|
|||
|
||||
$this->title = 'params list';
|
||||
|
||||
|
||||
?>
|
||||
<h1>Parameters</h1>
|
||||
|
||||
|
@ -23,4 +25,34 @@ $this->title = 'params list';
|
|||
<?= GridView::widget([
|
||||
'dataProvider' => $provider,
|
||||
'filterModel' => $searchModel,
|
||||
'columns' => [
|
||||
'id', 'title', 'type',
|
||||
[
|
||||
'label' => 'Icon',
|
||||
'value' => function (Parameter $model) {
|
||||
if ($model->icon) {
|
||||
$url = '/api/image?sha256=' . $model->getRelatedRecords()['icon']->sha256;
|
||||
return Html::a(Html::img($url, [ 'width' => 150, 'height' => 150 ]), $url, [ 'alt' => 'icon', 'target' => '_blank' ]);
|
||||
}
|
||||
},
|
||||
'format' => 'raw',
|
||||
],
|
||||
[
|
||||
'label' => 'Gray Icon',
|
||||
'value' => function (Parameter $model) {
|
||||
if ($model->iconGray) {
|
||||
$url = '/api/image?sha256=' . $model->getRelatedRecords()['iconGray']->sha256;
|
||||
return Html::a(Html::img($url, [ 'width' => 150, 'height' => 150 ]), $url, [ 'alt' => 'grayscale icon', 'target' => '_blank' ]);
|
||||
}
|
||||
},
|
||||
'format' => 'raw',
|
||||
],
|
||||
[
|
||||
'label' => 'Edit',
|
||||
'value' => function (Parameter $model) {
|
||||
return Html::a('Edit', '/list/edit?id=' . $model->id);
|
||||
},
|
||||
'format' => 'raw',
|
||||
],
|
||||
]
|
||||
]); ?>
|
||||
|
|
Loading…
Reference in New Issue