<p> <?php echo Html::a('新增商品', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'showOnEmpty' => false, 'tableOptions' => ['class' => 'table table-striped'], 'columns' => [['attribute' => 'goods_id', 'label' => '商品编号', 'headerOptions' => array('style' => 'width:50px;')], 'title', ['attribute' => 'goods_kind', 'label' => '分类', 'value' => function ($model, $key, $index, $column) { return MGoods::getGoodsKindOption($model->goods_kind); }, 'filter' => MGoods::getGoodsKindOption(), 'headerOptions' => array('style' => 'width:120px;')], ['attribute' => 'list_img_url', 'label' => '小图', 'format' => 'html', 'value' => function ($model, $key, $index, $column) { if (!empty($model->list_img_url)) { $list_img_url = '<img src=' . $model->list_img_url . ' width=64px height=64px>'; } else { $list_img_url = ''; } return $list_img_url; }, 'headerOptions' => array('style' => 'width:80px;')], ['attribute' => 'pub_userid', 'label' => '发布者', 'value' => function ($model, $key, $index, $column) { //return MGoods::getDetailCtrlOption($model->detail_ctrl); $user = MUser::findOne(['id' => $model->pub_userid]); return empty($user) ? "" : $user->username; }, 'headerOptions' => array('style' => 'width:90px;')], ['attribute' => 'status', 'format' => 'html', 'label' => '发布状态', 'value' => function ($model, $key, $index, $column) { if ($model->status == 0) { return "<span style='color:red'>" . MGoods::getStatusOption($model->status) . "</span>"; } else { return "<span style='color:green'>" . MGoods::getStatusOption($model->status) . "</span>"; } }, 'filter' => MGoods::getStatusOption(), 'headerOptions' => array('style' => 'width:120px;')], ['class' => 'yii\\grid\\ActionColumn', 'headerOptions' => array('style' => 'width:90px;')]]]); ?> </div>