here I have a model in yii2
<?php namespace appmodels; /** * 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 yiidbActiveRecord { 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' => 'تصاویر آگهی' ]; } }
when I want to submit the form I face with this error.
Getting unknown property: appmodelsCarAd::used_value
but as you see I have this field in my fields.
My table name is car_ad
.
what is the problem with my code?
Advertisement
Answer
Because this field is not present in the @property comment I guess you have added it after the model has been generated. If you have got the DB schema cached new fields are not fetched until cache is updated. Try to remove the cache for DB.