index.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * Author: lf
  4. * Blog: https://blog.feehi.com
  5. * Email: job@feehi.com
  6. * Created at: 2016-03-21 14:14
  7. */
  8. /**
  9. * @var $this yii\web\View
  10. * @var $dataProvider common\models\Menu
  11. * @var $searchModel backend\models\search\MenuSearch
  12. */
  13. use backend\grid\DateColumn;
  14. use backend\grid\GridView;
  15. use backend\grid\SortColumn;
  16. use backend\grid\StatusColumn;
  17. use backend\widgets\Bar;
  18. use common\libs\Constants;
  19. use common\models\Menu;
  20. use yii\helpers\Html;
  21. use yii\helpers\Url;
  22. use backend\grid\CheckboxColumn;
  23. use backend\grid\ActionColumn;
  24. $this->title = "Frontend Menus";
  25. $this->params['breadcrumbs'][] = Yii::t('app', 'Frontend Menus');
  26. ?>
  27. <div class="row">
  28. <div class="col-sm-12">
  29. <div class="ibox">
  30. <?= $this->render('/widgets/_ibox-title') ?>
  31. <div class="ibox-content">
  32. <?= Bar::widget() ?>
  33. <?= GridView::widget([
  34. 'dataProvider' => $dataProvider,
  35. 'filterModel' => $searchModel,
  36. 'layout' => '{items}',
  37. 'columns' => [
  38. [
  39. 'class' => CheckboxColumn::className(),
  40. ],
  41. [
  42. 'attribute' => 'name',
  43. 'label' => Yii::t('app', 'Name'),
  44. 'format' => 'html',
  45. 'value' => function ($model, $key, $index, $column) {
  46. $return = '';
  47. for ($i = 0; $i < $model['level']; $i++) {
  48. $return .= "&nbsp;&nbsp;&nbsp;&nbsp;";
  49. }
  50. return $return . $model['name'];
  51. }
  52. ],
  53. [
  54. 'attribute' => 'icon',
  55. 'label' => Yii::t('app', 'Icon'),
  56. 'format' => 'html',
  57. 'value' => function ($model) {
  58. return "<i class=\"fa {$model['icon']}\"></i>";
  59. }
  60. ],
  61. [
  62. 'attribute' => 'url',
  63. 'label' => Yii::t('app', 'Url'),
  64. 'value' => function($model){
  65. /** @var Menu $mddel */
  66. return $model->convertJSONStringToRelativeUrl();
  67. }
  68. ],
  69. [
  70. 'class' => SortColumn::className(),
  71. 'primaryKey' => function($model){
  72. return ["id" => $model["id"]];
  73. },
  74. 'label' => Yii::t('app', 'Sort')
  75. ],
  76. [
  77. 'attribute' => 'is_display',
  78. 'class' => StatusColumn::className(),
  79. 'label' => Yii::t('app', 'Is Display'),
  80. 'formName' => (new Menu)->formName() . '[is_display]',
  81. 'filter' => Constants::getYesNoItems()
  82. ],
  83. [
  84. 'class' => DateColumn::className(),
  85. 'attribute' => 'created_at',
  86. 'label' => Yii::t('app', 'Created At'),
  87. ],
  88. [
  89. 'class' => DateColumn::className(),
  90. 'attribute' => 'updated_at',
  91. 'label' => Yii::t('app', 'Updated At'),
  92. ],
  93. [
  94. 'class' => ActionColumn::className(),
  95. 'buttons' => [
  96. 'create' => function ($url, $model, $key) {
  97. return Html::a('<i class="fa fa-plus" aria-hidden="true"></i> ', Url::to([
  98. 'create',
  99. 'parent_id' => $model['id']
  100. ]), [
  101. 'title' => Yii::t('app', 'Create'),
  102. 'data-pjax' => '0',
  103. 'class' => 'btn-sm J_menuItem',
  104. ]);
  105. }
  106. ],
  107. 'template' => '{create} {view-layer} {update} {delete}',
  108. 'width' => '190px'
  109. ]
  110. ]
  111. ]) ?>
  112. </div>
  113. </div>
  114. </div>
  115. </div>