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">
<h1><?= Html::encode($this->title) ?></h1>
<?php //echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a('Create Publications', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'title',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>
What am I doing wrong?
Thanks.