4

I have this GridView widget in my index.php view:

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    //'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],

        //'user_id',
        'fname',
        'lname',
        'username',
        // 'password',
        // 'user_type',
        // 'creator',             
    ],
]); ?>

It obviously generates a table containing data from my database table. I want to get rid of the GridView widget and use other means of displaying data from the database. How do I do that?

One of the reasons why I don't want to use the GridView widget is that I want the display to not look like a table. Something like this, for example:

enter image description here

Is there any way? Thanks.

1

2 Answers 2

4

Use ListView widget for these purposes.

Example of basic usage:

<?= ListView::widget([
    'dataProvider' => $dataProvider,
    'itemView' => '_view',    
]) ?>

In _view view file you should place layout for a single user. Inside you can access the current user model through $model variable and get desired attributes values. Read more in official docs.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks! at first I used DetailView but I can't seem to customize it. now I just put <?= $model->fname; ?> and so on, now I can customize it whatever I want.
DetailView is for single model.
3

You can get the models in this way:

$myModels = $dataProvider->getModels();

and then iterate through $myModels array to access individual instances and manage the fields with html formatting you prefer

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.