我正在尝试使用Yii2 docs创建 ActiveDataProvider ,但我一直收到此错误:
Calling unknown method: app\models\UserKeysQuery::load()
控制器:
public function actionIndex()
{
$searchModel = new UserKeys();
$dataProvider = $searchModel::find()->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
型号:
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use app\models\UserKeys;
use yii\data\ActiveDataProvider;
/**
* This is the ActiveQuery class for [[Keys]].
*
* @see Keys
*/
class UserKeysQuery extends UsersQuery
{
public function search($params)
{
$query = UserKeys::find();
$query->joinWith(['user', 'licence']);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate()))
return $dataProvider;
$query->andFilterWhere([
'key' => Yii::$app->encrypter->encrypt($this->key)
]);
return $dataProvider;
}
}
我做错了什么?
答案 0 :(得分:0)
你扩展
class UserKeysQuery extends UsersQuery
但你使用
use app\models\UserKeys;
分配适当值的UserKeys或UsersKeys