|
2 | 2 |
|
3 | 3 | use yii\helpers\Html; |
4 | 4 | use yii\grid\GridView; |
| 5 | +use common\models\Commentstatus; |
| 6 | +use yii\grid\Column; |
5 | 7 |
|
6 | 8 | /* @var $this yii\web\View */ |
7 | 9 | /* @var $searchModel common\models\CommentSearch */ |
8 | 10 | /* @var $dataProvider yii\data\ActiveDataProvider */ |
9 | 11 |
|
10 | | -$this->title = 'Comments'; |
| 12 | +$this->title = '评论管理'; |
11 | 13 | $this->params['breadcrumbs'][] = $this->title; |
12 | 14 | ?> |
13 | 15 | <div class="comment-index"> |
14 | 16 |
|
15 | 17 | <h1><?= Html::encode($this->title) ?></h1> |
16 | 18 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
17 | 19 |
|
18 | | - <p> |
19 | | - <?= Html::a('Create Comment', ['create'], ['class' => 'btn btn-success']) ?> |
20 | | - </p> |
| 20 | + |
21 | 21 | <?= GridView::widget([ |
22 | 22 | 'dataProvider' => $dataProvider, |
23 | 23 | 'filterModel' => $searchModel, |
24 | 24 | 'columns' => [ |
25 | | - ['class' => 'yii\grid\SerialColumn'], |
| 25 | + // ['class' => 'yii\grid\SerialColumn'], |
26 | 26 |
|
27 | | - 'id', |
28 | | - 'content:ntext', |
29 | | - 'status', |
30 | | - 'create_time:datetime', |
31 | | - 'userid', |
| 27 | + //'id', |
| 28 | + [ |
| 29 | + 'attribute'=>'id', |
| 30 | + 'contentOptions'=>['width'=>'30px'], |
| 31 | + ], |
| 32 | + //'content:ntext', |
| 33 | + [ |
| 34 | + 'attribute'=>'content', |
| 35 | + 'value'=>'beginning', |
| 36 | +// 'value'=>function($model) |
| 37 | +// { |
| 38 | +// $tmpStr=strip_tags($model->content); |
| 39 | +// $tmpLen=mb_strlen($tmpStr); |
| 40 | + |
| 41 | +// return mb_substr($tmpStr,0,20,'utf-8').(($tmpLen>20)?'...':''); |
| 42 | +// } |
| 43 | + ], |
| 44 | + //'userid', |
| 45 | + [ |
| 46 | + 'attribute'=>'user.username', |
| 47 | + 'label'=>'作者', |
| 48 | + 'value'=>'user.username', |
| 49 | + ], |
| 50 | + //'status', |
| 51 | + [ |
| 52 | + 'attribute'=>'status', |
| 53 | + 'value'=>'status0.name', |
| 54 | + 'filter'=>Commentstatus::find() |
| 55 | + ->select(['name','id']) |
| 56 | + ->orderBy('position') |
| 57 | + ->indexBy('id') |
| 58 | + ->column(), |
| 59 | + 'contentOptions'=> |
| 60 | + function($model) |
| 61 | + { |
| 62 | + return ($model->status==1)?['class'=>'bg-danger']:[]; |
| 63 | + } |
| 64 | + ], |
| 65 | + // 'create_time:datetime', |
| 66 | + [ |
| 67 | + 'attribute'=>'create_time', |
| 68 | + 'format'=>['date','php:m-d H:i'], |
| 69 | + ], |
| 70 | + |
32 | 71 | // 'email:email', |
33 | 72 | // 'url:url', |
34 | 73 | // 'post_id', |
| 74 | + 'post.title', |
| 75 | + |
| 76 | + [ |
| 77 | + 'class' => 'yii\grid\ActionColumn', |
| 78 | + 'template'=>'{view} {update} {delete} {approve}', |
| 79 | + 'buttons'=> |
| 80 | + [ |
| 81 | + 'approve'=>function($url,$model,$key) |
| 82 | + { |
| 83 | + $options=[ |
| 84 | + 'title'=>Yii::t('yii', '审核'), |
| 85 | + 'aria-label'=>Yii::t('yii','审核'), |
| 86 | + 'data-confirm'=>Yii::t('yii','你确定通过这条评论吗?'), |
| 87 | + 'data-method'=>'post', |
| 88 | + 'data-pjax'=>'0', |
| 89 | + ]; |
| 90 | + return Html::a('<span class="glyphicon glyphicon-check"></span>',$url,$options); |
| 91 | + |
| 92 | + }, |
| 93 | + ], |
| 94 | + |
35 | 95 |
|
36 | | - ['class' => 'yii\grid\ActionColumn'], |
| 96 | + |
| 97 | + ], |
37 | 98 | ], |
38 | 99 | ]); ?> |
39 | 100 | </div> |
0 commit comments