<?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'tableOptions' => ['class' => 'table'], 'showHeader' => false, 'columns' => ['user_id', ['attribute' => 'user_id', 'label' => ''], ['label' => 'content', 'format' => 'html', 'value' => function ($model) { $text = '<div><strong><a href="' . Url::toRoute('advert/view?id=') . $model->id . '"> ' . $model->title . '</a></strong></div>'; $text .= '<div>' . $model->category->name . ' >> ' . $model->subcategory->name . '</div>'; $text .= '<br>'; $format = 'd M Y H:i'; $text .= date($format, $model->updated_at); return $text; }], 'price', 'views']]); ?> <?php $adv = new Advert(); echo '<pre>'; print_r($adv->getCities()); ?> </div> <?php /** * <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <?php $this->title = 'My Adverts'?> </head> <body> <div class="grid-view"> <?php
use yii\grid\GridView; use yii\grid\ActionColumn; use yii\jui\DatePicker; /* @var $this yii\web\View */ /* @var $searchModel app\models\AdvertCRUD */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Adverts'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="advert-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Advert', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'region_id', 'value' => 'region.name', 'label' => 'Region', 'filter' => Advert::getAllRegions()], ['attribute' => 'city_id', 'value' => 'city.name', 'label' => 'City', 'filter' => Advert::getCities()], ['attribute' => 'category_id', 'value' => 'category.name', 'label' => 'Category', 'filter' => Advert::getAllICategories()], ['attribute' => 'subcategory_id', 'value' => 'subcategory.name', 'label' => 'Subcategory', 'filter' => Advert::getSubcategories()], 'title', ['attribute' => 'updated_at', 'format' => ['date', 'php:d M Y, H:i']], 'views', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>