index.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. use yii\helpers\Html;
  3. use yii\grid\GridView;
  4. use yii\widgets\Pjax;
  5. use yii\helpers\ArrayHelper;
  6. use app\models\Categoriesblog;
  7. use kartik\select2\Select2;
  8. /* @var $this yii\web\View */
  9. /* @var $searchModel app\models\BlogPostsSearch */
  10. /* @var $dataProvider yii\data\ActiveDataProvider */
  11. $this->title = Yii::t('app', 'BlogPosts');
  12. $this->params['breadcrumbs'][] = $this->title;
  13. ?>
  14. <div class="posts-index">
  15. <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
  16. <p>
  17. <?= Html::a(Yii::t('app', 'Create BlogPosts'), ['create'], ['class' => 'btn btn-success']) ?>
  18. </p>
  19. <?php Pjax::begin(); ?>
  20. <?= GridView::widget([
  21. 'dataProvider' => $dataProvider,
  22. 'filterModel' => $searchModel,
  23. 'columns' => [
  24. ['class' => 'yii\grid\SerialColumn'],
  25. //'id',
  26. 'title',
  27. //'text:ntext',
  28. [
  29. 'attribute' => 'Picture',
  30. 'format' => 'raw',
  31. 'value' => function($model){
  32. return Html::img($model->getPicture(),['class' => 'img-responsive', 'style' => 'max-width : 150px ']);
  33. }
  34. ],
  35. [
  36. 'attribute' => 'cat_id',
  37. 'value' => 'category.title',
  38. 'filter' => Select2::widget([
  39. 'model' => $searchModel,
  40. 'attribute' => 'cat_id',
  41. 'data' => ArrayHelper::map(Categoriesblog::find()->all(), 'id', 'title'),
  42. 'options' => [
  43. 'placeholder' => Yii::t('app','Choose category'),
  44. 'allowClear' => true,
  45. ],
  46. ])
  47. ] ,
  48. 'description',
  49. 'key_words',
  50. ['class' => 'yii\grid\ActionColumn'],
  51. ],
  52. ]); ?>
  53. <?php Pjax::end(); ?></div>