Ошибка компиляции PHP при создании представлений и контроллеров с использованием Gii в YII2

Я создал модель обзора для таблицы. после этого при создании представлений и контроллеров для одной и той же таблицы выдается ошибка компиляции 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 для своих таблиц. Я получаю ошибку только за это.

Мой модельный класс
приложение \ модели \ Обзор
Поиск модели класса
приложение \ модели \ ReviewSearch
Класс контроллера
Приложение \ Контроллеры \ 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']);
}
}

0

Решение

Вам нужно переименовать ваш getRelation() метод как, вы переопределяете yii\db\ActiveRecordInterface::getRelation($name, $throwException = true), Так что это приведет к исключению, что getRelation Метод имеет недопустимое объявление.

0

Другие решения

Других решений пока нет …