Php Yii 2模型-类Yii\db\Query包含1个抽象方法,因此必须声明为抽象或实现其余方法
我是YII2的初学者。首先,我使用Gii扩展生成了我的模型和控制器。我已经在我的站点根目录下的config文件夹中找到的db.php文件中设置了我的数据库 然后,我在之前在管理模块中创建的模型上使用了CRUD生成器 当我现在转到管理模块时,出现以下错误:Php Yii 2模型-类Yii\db\Query包含1个抽象方法,因此必须声明为抽象或实现其余方法,php,yii,yii2,Php,Yii,Yii2,我是YII2的初学者。首先,我使用Gii扩展生成了我的模型和控制器。我已经在我的站点根目录下的config文件夹中找到的db.php文件中设置了我的数据库 然后,我在之前在管理模块中创建的模型上使用了CRUD生成器 当我现在转到管理模块时,出现以下错误: Class yii\db\Query contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (
Class yii\db\Query contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (yii\db\QueryInterface::indexBy)
我的模型:
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yii\db\ActiveRecord;
/**
* This is the model class for table "user".
*
* @property string $id
* @property string $name
* @property string $username
* @property string $pass
* @property string $email
* @property string $user_type
* @property string $date_joined
*
* @property Authassignment $authassignment
* @property Authitem[] $itemnames
*/
class User extends ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'user';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_type'], 'string'],
[['date_joined'], 'required'],
[['date_joined'], 'safe'],
[['name'], 'string', 'max' => 248],
[['username'], 'string', 'max' => 45],
[['pass'], 'string', 'max' => 256],
[['email'], 'string', 'max' => 60],
[['name', 'username', 'password', 'email', 'user_type', 'date_joined'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Name',
'username' => 'Username',
'password' => 'Password',
'email' => 'Email',
'user_type' => 'User Type',
'date_joined' => 'Date Joined',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getAuthassignment()
{
return $this->hasOne(Authassignment::className(), ['userid' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getItemnames()
{
return $this->hasMany(Authitem::className(), ['name' => 'itemname'])->viaTable('_authassignment', ['userid' => 'id']);
}
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
public function search($params)
{
$query = $this::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'date_joined' => $this->date_joined,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'username', $this->username])
->andFilterWhere(['like', 'pass', $this->pass])
->andFilterWhere(['like', 'email', $this->email])
->andFilterWhere(['like', 'user_type', $this->user_type]);
return $dataProvider;
}
}
我做错了什么
谢谢
编辑:
我已将Web服务器上的php升级到5.5.10,这已修复了此错误,我运行的是V5.4它可以通过更新Yi2框架来解决。
yii.db.Query
使用yii.db.QueryTrait
,其中实现了indexBy
方法。
请将您的Query.php
、QueryTrait.php
和QueryInterface.php
与
可以通过更新yii2框架来解决。
yii.db.Query
使用yii.db.QueryTrait
,其中实现了indexBy
方法。
请将您的Query.php
、QueryTrait.php
和QueryInterface.php
与
如果使用MAMP,那是因为XCache。
请尝试在MAMP首选项中禁用它。如果使用MAMP,那是因为XCache。
请尝试在MAMP首选项中禁用它。刚刚尝试了这个,它在瞬间工作,然后刷新页面再次导致错误。我再次替换了文件并收到了相同的错误。只是尝试了一下,它在一瞬间起作用,然后刷新页面再次导致错误。我再次替换了这些文件,并收到了相同的错误。您刚刚保存了我的一天;)你刚刚救了我一天;)
Cannot instantiate abstract class app\models\User