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

0

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

Мое приложение класса моделей\модели\Обзор Поиск класса модели приложения \models\ReviewSearch Controller Class 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']);
    }
}
Теги:
yii2
compiler-errors
crud

1 ответ

0
Лучший ответ

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

  • 0
    Ты прав..

Ещё вопросы

Сообщество Overcoder
Наверх
Меню