Created
May 27, 2018 17:29
-
-
Save calcio/aef0ec42b6854e6e4b98ada989a61155 to your computer and use it in GitHub Desktop.
Index Product customizada e fazendo uso das Relations do Yii2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use yii\helpers\Html; | |
use yii\grid\GridView; | |
use yii\widgets\Pjax; | |
/* @var $this yii\web\View */ | |
/* @var $searchModel app\modules\admin\models\ProductSearch */ | |
/* @var $dataProvider yii\data\ActiveDataProvider */ | |
$this->title = Yii::t('app', 'Products'); | |
$this->params['breadcrumbs'][] = $this->title; | |
?> | |
<div class="product-index"> | |
<h1><?= Html::encode($this->title) ?></h1> | |
<?php // echo $this->render('_search', ['model' => $searchModel]); ?> | |
<p> | |
<?= Html::a(Yii::t('app', 'Create Product'), ['create'], ['class' => 'btn btn-success']) ?> | |
</p> | |
<?php Pjax::begin(); ?> | |
<?= GridView::widget([ | |
'dataProvider' => $dataProvider, | |
'filterModel' => $searchModel, | |
'columns' => [ | |
[ | |
'attribute' => 'id', | |
'headerOptions' => [ | |
'class' => 'col-sm-1 text-center' | |
], | |
'contentOptions' => [ | |
'class' => 'text-center' | |
], | |
], | |
[ | |
'attribute' => 'category_id', | |
'headerOptions' => [ | |
'class' => 'col-sm-2 text-center' | |
], | |
'value' => 'category.name', | |
'filter' => $listCategories | |
], | |
'name', | |
[ | |
'attribute' => 'status', | |
'filter' => [ | |
$searchModel::STATUS_ACTIVE => $searchModel::STATUS_ACTIVE_STRING , | |
$searchModel::STATUS_INACTIVE => $searchModel::STATUS_INACTIVE_STRING | |
], | |
'headerOptions' => [ | |
'class' => 'col-sm-2 text-center' | |
], | |
'contentOptions' => [ | |
'class' => 'text-center' | |
], | |
'format' => 'statusHighlighted', | |
], | |
[ | |
'attribute' => 'highligt', | |
'headerOptions' => [ | |
'class' => 'col-sm-1 text-center' | |
], | |
'filter' => [ | |
$searchModel::STATUS_ACTIVE => $searchModel::STATUS_HIGHLIGHTED_STRING , | |
$searchModel::STATUS_INACTIVE => $searchModel::STATUS_UNHIGHLIGHTED_STRING | |
], | |
'contentOptions' => [ | |
'class' => 'text-center' | |
], | |
'format' => 'highlight' | |
], | |
[ | |
'attribute' => 'price', | |
'format' => 'currency', | |
'headerOptions' => [ | |
'class' => 'col-sm-2 text-center' | |
], | |
'contentOptions' => [ | |
'class' => 'text-right' | |
], | |
], | |
[ | |
'class' => 'yii\grid\ActionColumn', | |
'header' => 'Actions', | |
'headerOptions' => [ | |
'class' => 'col-sm-1 text-center' | |
], | |
'contentOptions' => [ | |
'class' => 'text-center' | |
], | |
'buttons' => [ | |
'delete' => function ($url, $model) { | |
return Html::a('<span class="glyphicon glyphicon-trash text-danger"></span>', $url, [ | |
'name' => 'Delete', | |
'data-confirm' => sprintf( | |
'Do you wish delete categoty %s?', | |
$model->name | |
), | |
'data-method' => 'POST' | |
]); | |
}, | |
] | |
], | |
], | |
]); ?> | |
<?php Pjax::end(); ?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment