index.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. use app\models\base\TopSlider;
  3. use yii\helpers\Html;
  4. use yii\helpers\Url;
  5. use yii\grid\ActionColumn;
  6. use yii\grid\GridView;
  7. /* @var $this yii\web\View */
  8. /* @var $dataProvider yii\data\ActiveDataProvider */
  9. //print_a($dataProvider->query->createCommand()->rawSQL);
  10. //print_a($dataProvider->getModels());
  11. //$dataProvider->getModels()->toArray([]);exit;
  12. $this->title = 'Содержимое слайдера';
  13. $this->params['breadcrumbs'][] = $this->title;
  14. ?>
  15. <div class="top-slider-index">
  16. <p>
  17. <?= Html::a('Добавить новость', ['create'], ['class' => 'btn btn-success']) ?>
  18. </p>
  19. <?= GridView::widget([
  20. 'dataProvider' => $dataProvider,
  21. 'columns' => [
  22. ['class' => 'yii\grid\SerialColumn'],
  23. [
  24. 'attribute'=>'новость',
  25. 'value' => 'post_id'
  26. ],
  27. [
  28. 'attribute' => 'Фото',
  29. 'format' => 'html',
  30. 'value' => function ($model) {return Html::img(Yii::getAlias('@web').'/images/news/news/'. $model['id'].".jpg", ['width' => '90px']);},
  31. ],
  32. [
  33. 'attribute'=>'Заголовок',
  34. 'format' => 'html',
  35. 'value' => function ($model) {return Html::a( $model['title'], '/news/'.$model['id'] );},
  36. ],
  37. [
  38. 'attribute'=>'Дата начала',
  39. 'value' => 'published_from',
  40. ],
  41. [
  42. 'attribute'=>'Дата окончания',
  43. 'value' => 'published_to',
  44. ],
  45. [
  46. 'class' => ActionColumn::className(),
  47. 'urlCreator' => function ($action, $model, $key, $index, $column) {
  48. return Url::toRoute([$action, 'id' => $model['ts_id']]);
  49. }
  50. ],
  51. ],
  52. ]); ?>
  53. </div>