带有 ->all() 的 Yii 2 ActiveDataProvider 查询给出“调用数组上的成员函数 andFilterWhere()"错误 [英] Yii 2 ActiveDataProvider query with ->all() gives "Call to a member function andFilterWhere() on array" error

查看:18
本文介绍了带有 ->all() 的 Yii 2 ActiveDataProvider 查询给出“调用数组上的成员函数 andFilterWhere()"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要传递 ActiveDataProvider 对象来查看,但我不明白为什么会这样:

I need to pass ActiveDataProvider object to view and I can't understand why this:

$query = Incarico::find();

$dataProvider = new ActiveDataProvider([
    'query' => $query,
]);

有效,而这个:

$query = Incarico::find()
    ->joinWith('allegatos')           
    ->all();

$dataProvider = new ActiveDataProvider([
    'query' => $query,
]);

给我以下错误:

在数组上调用成员函数andFilterWhere()

Call to a member function andFilterWhere() on array

推荐答案

你不应该应用 all()$query 因为 ActiveDataProviderquery 属性在您传递该查询的结果时需要有效的 ActiveQuery 实例.

You should not apply all() to $query since ActiveDataProvider query property expects valid ActiveQuery instance while you are passing results of that query.

这篇关于带有 ->all() 的 Yii 2 ActiveDataProvider 查询给出“调用数组上的成员函数 andFilterWhere()"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆