2014-11-06 34 views
0

我已經爲該表創建了Review模型。之後,當爲相同的表創建視圖和控制器時,它顯示PHP編譯錯誤。PHP在YII2中使用Gii創建視圖和控制器時編譯錯誤

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創建此相同高級它顯示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

請向我們展示您的「評論」模型 – 2014-11-06 10:31:39

+0

我剛剛發現它是因爲我的外鍵關係。沒有外鍵關係,我可以創建**視圖**和**控制器**。但是不知道我的外鍵有什麼問題。 :( – 2014-11-06 11:54:42

+0

親愛的,請重命名你的'getRelation'方法並給我結果 – 2014-11-06 11:56:39

回答

0

你需要的,你要重寫yii\db\ActiveRecordInterface::getRelation($name, $throwException = true)重命名getRelation()方法。所以這會造成一個例外,即getRelation方法的聲明無效。

+0

你是對的.. – 2014-11-06 12:50:56