M
M
Miri_Skava2018-10-12 16:05:35
Yii
Miri_Skava, 2018-10-12 16:05:35

Why is the error "The "dataProvider" property must be set." thrown?

Unable to display data from db in gridview on layout\cuba

use common\models\Schedule;
use yii\data\ActiveDataProvider;

class LayoutsController extends \yii\web\Controller
{
    public $dataProvider;
    public function actionCuba()
    {
        $dataProvider=Schedule::find()->all();
        return $this->render('cuba',[
            'dataProvider'=>$dataProvider,
        ]);
    }

}

<?= GridView::widget([
                             'dataProvider' => $dataProvider,
                             'columns' => [
                                 ['class' => 'yii\grid\SerialColumn'],
                                 [
                                     'attribute' => 'week_id',
                                     'value' => 'week.name',
                                 ],

                                 ['class' => 'yii\grid\ActionColumn'],
                             ],
                         ]); ?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Arman, 2018-10-12
@Arik

The all method started returning dataProvider?
https://github.com/yiisoft/yii2/blob/master/docs/g...

L
Lander, 2018-10-12
@usdglander

$dataProvider = new ActiveDataProvider(['query' => Schedule::find()]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question