1

Using gii, I created a model based on a database table and then CRUD for the model. One of the columns is showing either 1 or 2 as they are stored in the database. To create new, it was easy using a ActiveForm->dropDownList() widget:

<?= $form->field($model, 'type')->dropDownList(['1'=>'Role', '2'=>'Permission'], ['prompt'=>'Select Auth Item Type']) ?>

How to use GridView and show Role instead of 1 and Permission instead 2?

1 Answer 1

1

In gridview you can use value

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        .........
        [
            'attribute' => 'type',
            'label' => 'Type',
            'format' => 'raw',
            'value' => function ($model) {                      
                 if ( $model->type == 1) {
                    return 'Role';
                 } else {
                    return 'Permission';
                 }
            },
        ],
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.