以下代码用于显示gridview,但它显示"数据提供者"错误。
模型:
Subcategory.php:
public function getCountries()
{
return $this->hasOne(Subcategories::className(),['id'=>'catid']);
}
查看:
subcategory.php: 我添加了以下编码,以便在网格视图中查看已保存的数据。
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns'=>[
['class'=>'yii\grid\SerialColumn'],
'id',
'categoryname',
[
'attribute' => subcategory,
'value'=>getCountries.subcatname,
],
['class'=>'yii\grid\ActionColumn'],
],
]); ?>
CONTROLLER
public function actionView2()
{
$dataProvider = new ActiveDataProvider([
'query' => Subcategory::find(),
'pagination' => [
'pageSize' => 20
]
]);
$posts = $dataProvider->getModels();
return $this->render('subcategory' [
'dataProvider' => $dataProvider,
]);
}
我已应用此编码但出现以下错误:
PHP Notice – yii\base\ErrorException Undefined variable: dataProvider