2016-07-30 170 views
2

在這裏我已經在yii2獲得未知屬性異常的yii2

<?php 

namespace app\models; 

/** 
* This is the model class for table "car_ad". 
* 
* @property integer $id 
* @property integer $brand_id 
* @property integer $sub_brand_id 
* @property integer $sell_type 
* @property integer $year 
* @property integer $the_function 
* @property integer $fuel_type_id 
* @property integer $gearbox 
* @property integer $sell_mode 
* @property integer $real_price 
* @property integer $prepayment 
* @property integer $installment_price 
* @property integer $no_installments 
* @property integer $delivery_time_id 
* @property integer $installments_period 
* @property integer $body_status_id 
* @property integer $body_color_id 
* @property integer $inside_color_id 
* @property integer $number_type 
* @property string $description 
* @property integer $ad_type_id 
* @property integer $provice_id 
* @property integer $city_id 
* @property string $address 
* @property string $lang 
* @property string $lat 
* @property string $creation_date 
* @property integer $user_id 
*/ 
class CarAd extends \yii\db\ActiveRecord 
{ 
    public $imageFiles; 
    /** 
    * @inheritdoc 
    */ 
    public static function tableName() 
    { 
     return 'car_ad'; 
    } 

    /** 
    * @inheritdoc 
    */ 
    public function rules() 
    { 
     return [ 
      [['brand_id', 'sub_brand_id', 'sell_type', 'year', 'used_value', 'fuel_type_id', 'gearbox', 'body_status_id', 'body_color_id', 'number_type', 'ad_type_id', 'provice_id', 'city_id', 'address', 'lang', 'lat', 'creation_date', 'user_id'], 'required'], 
      [['brand_id', 'sub_brand_id', 'sell_type', 'year', 'fuel_type_id', 'used_value ', 'gearbox', 'sell_mode', 'real_price', 'prepayment', 'installment_price', 'no_installments', 'delivery_time_id', 'installments_period', 'body_status_id', 'body_color_id', 'inside_color_id', 'number_type', 'ad_type_id', 'provice_id', 'city_id', 'creation_date', 'user_id'], 'integer'],    
      [['description'], 'string'], 
      [['address', 'lang', 'lat'], 'string', 'max' => 512], 
      [['imageFiles'], 'file', 'skipOnEmpty' => true, 'extensions' => 'png, jpg', 'maxFiles' => 10], 
     ]; 
    } 

    public function upload() 
    { 

     foreach ($this->imageFiles as $file) { 
      $image = New CarAdImage();    
      $image->image = $file->baseName . '.' . $file->extension; 
      $image->car_ad_id = $this->id; 
      $image->save(); 
      $file->saveAs('img/car_ad/' . $file->baseName . '.' . $file->extension); 
     }   
    } 

    /** 
    * @inheritdoc 
    */ 
    public function attributeLabels() 
    { 
     return [ 
      'id' => 'شناسه', 'brand_id' => 'برند', 'sub_brand_id' => 'مدل','sell_type' => 'فروش به صورت', 
      'year' => 'سال','used_value' => 'کارکرد','fuel_type_id' => 'سیستم سوخت','gearbox' => 'گیربکس', 
      'sell_mode' => 'نوع فروش','real_price' => 'قیمت نقدی','prepayment' => 'پیش پرداخت','installment_price' => 'مبلغ هر قسط','no_installments' => 'تعداد اقساط','delivery_time_id' => 'موعد تحویل', 
      'installments_period' => 'دوره پرداخت', 
      'body_status_id' => 'وضعیت بدنه', 
      'body_color_id' => 'رنگ بدنه', 
      'inside_color_id' => 'رنگ داخل', 
      'number_type' => 'نوع پلاک', 
      'description' => 'توضیحات اضافی', 
      'ad_type_id' => 'نوع آگهی', 
      'provice_id' => 'استان', 
      'city_id' => 'شهرستان', 
      'address' => 'آدرس', 
      'lang' => 'طول جغرافیایی', 
      'lat' => 'عرض جغرافیایی', 
      'creation_date' => 'تاریخ ایجاد', 
      'user_id' => 'کاربر ایجاد کننده', 
      'imageFiles' => 'تصاویر آگهی' 
     ]; 
    } 
} 
時,我想我提交面對這個錯誤的形式

的典範。

Getting unknown property: app\models\CarAd::used_value

但你看,我在我的領域這一領域。 我的表名是car_ad。 我的代碼有什麼問題?

回答

3

因爲這個字段不存在於@property註釋中,我猜你已經在模型生成後添加了它。如果已獲取緩存的數據庫模式,則在更新緩存之前,不會提取新的字段。嘗試刪除數據庫的緩存。

+0

我已經改變了數據庫中的字段,首先它的名字是the_function,並且我得到了同樣的錯誤,然後我重命名了它,沒有任何更改 –

+0

因此,在您的數據庫連接配置中沒有''enableSchemaCache'=> true'? – Bizley

+0

no there isn; t。我已經在我的動作中刷新了架構:( –