Undefined variable: dataProvider

I installed latest yii version. and created CRUD using gii. I dont know what is wrong with it. I found error.

PHP Notice – yii\base\ErrorException

Undefined variable: dataProvider.

My script at controller




<?php


namespace app\controllers;


class ProductController extends \yii\web\Controller

{

    public function actionIndex()

    {

        return $this->render('index');

    }


}

At view


<?php


use yii\helpers\Html;

use yii\grid\GridView;


/* @var $this yii\web\View */

/* @var $searchModel app\models\TblProductSearch */

/* @var $dataProvider yii\data\ActiveDataProvider */


$this->title = 'Tbl Products';

$this->params['breadcrumbs'][] = $this->title;

?>

<div class="tbl-product-index">


    <h1><?= Html::encode($this->title) ?></h1>

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>


    <p>

        <?= Html::a('Create Tbl Product', ['create'], ['class' => 'btn btn-success']) ?>

    </p>


    <?= GridView::widget([

        'dataProvider' => $dataProvider,

        'filterModel' => $searchModel,

        'columns' => [

            ['class' => 'yii\grid\SerialColumn'],


            'id',

            'prod_name',

            'prod_image',

            'prod_size',

            'prod_pack_size',

            // 'date_created',

            // 'date_edited',

            // 'active',


            ['class' => 'yii\grid\ActionColumn'],

        ],

    ]); ?>


</div>

Can u explain me with code how to overcome with it…

In Your Controller.

It should be something like:




namespace app\controllers;


use app\models\TblProductSearch; 


class ProductController extends \yii\web\Controller

{

    public function actionIndex()

    {

        $searchModel = new TblProductSearch();

        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);


        return $this->render('index', [

            'searchModel' => $searchModel,

            'dataProvider' => $dataProvider,

        ]);

    }


}



Regards