Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 Display Data from the Database Without Using GridView

Tags:

php

gridview

yii2

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.

like image 418
kaynewilder Avatar asked Mar 16 '23 21:03

kaynewilder


1 Answers

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.

like image 100
arogachev Avatar answered Apr 25 '23 01:04

arogachev