【问题标题】:Passing data from a controller to a gridview fails with将数据从控制器传递到网格视图失败
【发布时间】:2016-07-18 12:15:40
【问题描述】:

我一直在尝试将模型数据数组从控制器传递到网格视图到网格视图,但出现以下错误:

The "query" property must be an instance of a class that implements the 
QueryInterface e.g. yii\db\Query or its subclasses.

这是控制器代码:

 public function actionAddunits($id){

  $countUnits = Unitslocation::find()->where(['officelocationid'=>$id])->count();
    if(count($countUnits)>0){

   $dataProvider = new ActiveDataProvider([
        'query' =>Unitslocation::find()->where(['officelocationid'=>$id])->all()
    ]);

      return $this->render('assignunits', ['dataProvider'=>$dataProvider]);

    }else{
        return 0;
    }

}

视图(assignunits.php)

<?php
echo GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
    // ...
    [
        'class' => 'yii\grid\CheckboxColumn',
        // you may configure additional properties here
    ],
],]);

?>

可能出了什么问题?

【问题讨论】:

    标签: php gridview yii2 yii-extensions yii2-advanced-app


    【解决方案1】:

    ActivedataProvider 需要query。在您的情况下,您发送query(all()) 的结果。

    删除您的query 中的all()

    $query = Unitslocation::find()->where(['officelocationid'=>$id]);
    $dataProvider = new ActiveDataProvider([
        'query' => $query,
    ]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 2019-07-03
      • 1970-01-01
      • 1970-01-01
      • 2017-11-30
      相关资源
      最近更新 更多