duandaotui5633 2016-07-18 12:15
浏览 67
已采纳

将数据从控制器传递到gridview失败

I have been trying to pass an array of model data from a controller to a gridview to a gridview but I get an error of:

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

This is the controller code:

 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;
    }

}

The view (assignunits.php)

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

?>

What could be wrong?

  • 写回答

1条回答 默认 最新

  • dqudtskm49788 2016-07-18 12:22
    关注

    ActivedataProvider needs a query. In your case you send the result of the query(all()).

    Remove all() in your query.

    $query = Unitslocation::find()->where(['officelocationid'=>$id]);
    $dataProvider = new ActiveDataProvider([
        'query' => $query,
    ]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效