Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting unknown property Exception in yii2

Tags:

php

yii2

here I have a model in 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' => 'تصاویر آگهی'
        ];
    }
}

when I want to submit the form I face with this error.

Getting unknown property: app\models\CarAd::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?

like image 660
Behzad Hassani Avatar asked Jul 30 '16 15:07

Behzad Hassani


People also ask

How does Yii manage PHP exceptions?

In code where an exception might occur, the developer can throw () an exception to a robust error handler. How Does Yii Manage These? In Yii, non-fatal PHP errors (e.g. warnings and notices) are routed into catchable exceptions so you can decide how to react and respond to them.

Are all errors logged in Yii?

All errors in Yii are logged depending on how you've set them up. You may also be interested in my tutorial about Sentry and Rollbar for logging in Yii: Finding production errors can be difficult without proper error handling or a cloud-based logging service.

What are the configuration options for ErrorHandler in Yii?

More broadly, Yii offers a variety of configuration options for errorHandler for redirection and data gathering: The route (e.g. site/error) to the controller action that will be used to display external errors. Maximum number of source code lines to be displayed. Maximum number of trace source code lines to be displayed.


1 Answers

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.

like image 62
Bizley Avatar answered Oct 20 '22 07:10

Bizley