我一直在尝试将一组模型数据从控制器传递到gridview到gridview但是我收到错误:
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
],
],]);
?>
可能出现什么问题?
答案 0 :(得分:2)
ActivedataProvider
需要query
。在您的情况下,您发送query(all())
的结果。
删除all()
中的query
。
$query = Unitslocation::find()->where(['officelocationid'=>$id]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);