title: Undefined variable: dataProvider in yii2 kartik grid
body: <p>I'm trying to learn about <strong>kartik grid view</strong> and I'm having trouble with dataProvider.</p>
  
  <p><strong>Controller Code</strong></p>
  
  <p>this is the full controller code (not all though, i just show the code until code containing the dataProvider that i asked why it's undefined)</p>
  
  <pre><code>class SiteController extends Controller {
   public function actions()
   {
  return [
      'error' =&gt; [
          'class' =&gt; 'yii\web\ErrorAction',
      ],
      'captcha' =&gt; [
          'class' =&gt; 'yii\captcha\CaptchaAction',
          'fixedVerifyCode' =&gt; YII_ENV_TEST ? 'testme' : null,
      ],
  ];
  }
  
  
  public function actionIndex()
  {
  if (!Yii::$app-&gt;user-&gt;isGuest){
  if (Yii::$app-&gt;user-&gt;identity-&gt;akses === '1'){
      return $this-&gt;render('knpr/knpr-home');
  } else if (Yii::$app-&gt;user-&gt;identity-&gt;akses === '2') {
      return $this-&gt;render('prov/prov-home');
  } else if (Yii::$app-&gt;user-&gt;identity-&gt;akses === '3') {
      return $this-&gt;render('kabkot/kabkot-home');
  } else if (Yii::$app-&gt;user-&gt;identity-&gt;akses === '4') {
      return $this-&gt;render('multiregional/multiregional-home');
  }
    }
  //return $this-&gt;render('home-knpr');
  }
  
  
  public function actionLogin()
  {   $this-&gt;layout = 'main-login';
  if (!Yii::$app-&gt;user-&gt;isGuest) {
      return $this-&gt;goHome();
     }
  
    $model = new LoginForm();
    if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $model-&gt;login()) {
      return $this-&gt;goBack();
     }
  return $this-&gt;render('login', [
      'model' =&gt; $model,
  ]);
    }
  
  public function actionLogout()
  {
  Yii::$app-&gt;user-&gt;logout();
  return $this-&gt;redirect(['site/login'])-&gt;send();
   }
  
  public function actionKnprHome()
   {
      $totalCount = Yii::$app-&gt;db-&gt;createCommand('SELECT COUNT(*) FROM m_admin') -&gt; queryScalar();
  
  $dataProvider = new SqlDataProvider([
      'db'  =&gt; Yii::$app-&gt;db,
      'sql' =&gt; 'SELECT * FROM m_admin',
      'totalCount' =&gt; $totalCount,
      'sort' =&gt; false,
      'pagination' =&gt; [
          'pageSize' =&gt; $count,
      ],
  ]);
  
  return $this-&gt;render('knpr/knpr-home', array('dataProvider' =&gt; $dataProvider));
  
    }
  </code></pre>
  
  <p><strong>View Code</strong></p>
  
  <pre><code>&lt;?php echo GridView::widget([ 
  'dataProvider' =&gt; $dataProvider,
  'showOnEmpty' =&gt; true,
  'emptyCell' =&gt; true,
  'column' =&gt; [
      'username',
      'password',
      'akses',
      'kode_daerah',
      'authKey',
      'id',
      ],
  'pjax' =&gt; true,
  ]);   ?&gt;
  </code></pre>
  
  <p>and the output is : </p>
  
  <blockquote>
    <p>Undefined variable: dataProvider</p>
  </blockquote>
  
  <p>error : 
  <a href="https://i.stack.imgur.com/2Sk9i.png" rel="nofollow noreferrer">undefined var : dataProvider</a></p>
  
  <p><a href="https://i.stack.imgur.com/RoSCi.png" rel="nofollow noreferrer">more</a></p>
  
  <p><a href="https://i.stack.imgur.com/P9Zsc.png" rel="nofollow noreferrer">more</a></p>
  
  <p><a href="https://i.stack.imgur.com/t9b5Y.png" rel="nofollow noreferrer">more</a></p>
  
  <p>Please suggest.</p>