gpt4 book ai didi

php - 在YII2中使用Gii创建 View 和 Controller 时,PHP编译错误

转载 作者:行者123 更新时间:2023-12-02 11:03:37 25 4
gpt4 key购买 nike

我已经为表创建了Review模型。之后,在为同一表创建 View 和 Controller 时,它显示PHP编译错误。

PHP Compile Error – yii\base\ErrorException

Declaration of app\models\Review::getRelation() must be compatible with yii\db\ActiveRecordInterface::getRelation($name, $throwException = true)

这是完整的错误页面
http://pastebin.com/kf8RFun8
我已经为表创建了其余的MVC。我只为此错误。

我的模型类(class)
app \ models \ Review
搜索模型类
app \ models \ ReviewSearch
Controller 类
app \ controllers \ ReviewController

注意:在Yii2-Advanced中创建相同代码时,它显示 Error (#64) Internal Server Error
评论模型:
<?php

namespace app\models;

use Yii;

/**
* This is the model class for table "review".
*
* @property string $id
* @property string $title
* @property string $reviewer_id
* @property string $timestamp
* @property string $description
* @property string $organization_id
* @property integer $rating
* @property string $relation_id
* @property integer $send_msg
* @property string $org_contact_email
* @property string $org_contact_msg
*
* @property Answer[] $answers
* @property Reviewer $reviewer
* @property Organization $organization
* @property Relation $relation
*/
class Review extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'review';
}

/**
* @inheritdoc
*/
public function rules()
{
return [
[['title', 'reviewer_id', 'organization_id', 'rating', 'relation_id'], 'required'],
[['reviewer_id', 'organization_id', 'rating', 'relation_id', 'send_msg'], 'integer'],
[['timestamp'], 'safe'],
[['title'], 'string', 'max' => 45],
[['description'], 'string', 'max' => 2000],
[['org_contact_email'], 'string', 'max' => 60],
[['org_contact_msg'], 'string', 'max' => 1000]
];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'title' => 'Title',
'reviewer_id' => 'Reviewer ID',
'timestamp' => 'Timestamp',
'description' => 'Description',
'organization_id' => 'Organization ID',
'rating' => 'Rating',
'relation_id' => 'Relation ID',
'send_msg' => 'Send Msg',
'org_contact_email' => 'Org Contact Email',
'org_contact_msg' => 'Org Contact Msg',
];
}

/**
* @return \yii\db\ActiveQuery
*/
public function getAnswers()
{
return $this->hasMany(Answer::className(), ['review_id' => 'id']);
}

/**
* @return \yii\db\ActiveQuery
*/
public function getReviewer()
{
return $this->hasOne(Reviewer::className(), ['id' => 'reviewer_id']);
}

/**
* @return \yii\db\ActiveQuery
*/
public function getOrganization()
{
return $this->hasOne(Organization::className(), ['id' => 'organization_id']);
}

/**
* @return \yii\db\ActiveQuery
*/
public function getRelation()
{
return $this->hasOne(Relation::className(), ['id' => 'relation_id']);
}
}

最佳答案

您需要重命名getRelation()方法,因为您要覆盖yii\db\ActiveRecordInterface::getRelation($name, $throwException = true)。因此,这将导致getRelation方法具有无效声明的异常。

关于php - 在YII2中使用Gii创建 View 和 Controller 时,PHP编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26772724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com