Gii CRUD example not working

I am basically following the Gii bit of the Guide to Yii2. But my view (index.php) gives an error "Undefined variable: dataProvider". In fact, the view cannot see the variables passed to it by the controller (dataProvider and searchModel).

Controller code:

public function actionIndex()

{


    $searchModel = new PublicationsSearch();


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





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


        'searchModel' => $searchModel,


        'dataProvider' => $dataProvider,


    ]);


}

View (index.php) code:

<?php

use yii\helpers\Html;

use yii\grid\GridView;

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

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

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

$this->title = ‘Publications’;

$this->params[‘breadcrumbs’][] = $this->title;

?>

<div class="publications-index">

&lt;h1&gt;&lt;?= Html::encode(&#036;this-&gt;title) ?&gt;&lt;/h1&gt;


&lt;?php  //echo &#036;this-&gt;render('_search', ['model' =&gt; &#036;searchModel]); ?&gt;





&lt;p&gt;


    &lt;?= Html::a('Create Publications', ['create'], ['class' =&gt; 'btn btn-success']) ?&gt;


&lt;/p&gt;





&lt;?= GridView::widget([


    'dataProvider' =&gt; &#036;dataProvider,


    'filterModel' =&gt; &#036;searchModel,


    'columns' =&gt; [


        ['class' =&gt; 'yii&#092;grid&#092;SerialColumn'],





        'id',


        'title',





        ['class' =&gt; 'yii&#092;grid&#092;ActionColumn'],


    ],


]); ?&gt;

</div>

What am I doing wrong?

Thanks.

Could you paste the full error message, please? It should throw a file and a line alongside the message.




PHP Notice – yii\base\ErrorException

Undefined variable: dataProvider

1. in views\publications\index.php at line 26

2. in views\publications\index.php – yii\base\ErrorHandler::handleError(8, 'Undefined variable: dataProvider', 'C:\web projects\newsmanager2\bas...', 26, ...) at line 26



Thanks.

Hum, it may sound extrange, but you are sure that the method called in the Controller is that and not another one? Y mean, if you put a var_dump in the controller method (with a die after it to be able to see it easily) it is shown, right?

Hey thanks for that, you are absolutely right. There were two PublicationsController.php files, one in models and one in controllers. Deleted the erroneous file and bingo it’s all working! Many many thanks.