public function init() { parent::init(); $this->contentOptions = ['class' => 'align-center']; $this->content = function ($model, $key, $index, $gridView) { return Constants::getStatusItems($model->status); }; }
<?php echo $form->field($model, 'url')->textInput(['maxlength' => 512]); ?> <?php echo $form->field($model, 'target')->radioList(Constants::getTargetItems()); ?> <?php echo $form->field($model, 'thumb')->fileInput(['class' => 'da-custom-file']); ?> <?php echo $form->field($model, 'description')->textarea(['maxlength' => 512]); ?> <?php echo $form->field($model, 'sort_num')->textInput(); ?> <?php echo $form->field($model, 'status')->radioList(Constants::getStatusItems()); ?> <?php echo $form->defaultButtons(); ActiveForm::end();
use source\models\User; use source\libs\Constants; use source\modules\rbac\models\Role; /* @var $this yii\web\View */ /* @var $searchModel source\models\search\UserSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = '注册会员'; echo source\libs\Message::getMessage(); ?> <div class="page-header"> <h3> <strong><?php echo Html::encode($this->title); ?> </strong> <div class="pull-right"> <?php echo Html::a('<span class="glyphicon glyphicon-plus"></span> ' . LsYii::gT('添加' . $this->title), ['/user/member/create'], ['class' => 'btn btn-primary']); ?> </div> </h3> </div> <div class="user-index"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'username', 'value' => 'username'], ['attribute' => 'email', 'value' => 'email'], ['attribute' => 'status', 'filter' => Constants::getStatusItems(), 'content' => function ($model, $key, $index, $gridView) { return Constants::getStatusItems($model->status); }], ['attribute' => 'role', 'value' => 'role', 'filter' => Role::getMemberItems()], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
public function getStatusText() { return Constants::getStatusItems($this->status); }