PHP Compile Error – yii\base\ErrorException

I have created Review model for the table. after that while creating views and controllers for the same table it shows PHP Compile error.


PHP Compile Error – yii\base\ErrorException


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

Here is the full error page pastebin. com/kf8RFun8 . I have created rest of the MVCs for my tables. I get error only for this.

My Model Class app\models\Review Search Model Class app\models\ReviewSearch Controller Class app\controllers\ReviewController

Below is my Review model


<?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']);

    }

}




Note: while creating this same in Yii2-Advanced It shows Error (#64) Internal Server Error

Have you modified the model or it was generated by Gii like that?

I didn’t change anything in model. It was generated by Gii.

I just found that its because of my foreign key relation. Without foreign key relation I can Create Views and Controller . But dont know whats wrong in my foreign key. :(

I found out the mistake… Its because of the name Relation which is an invalid declaration.