I have added a new field "sell_price_default" in my "Food" table. and then i manually added a variable for that field in my Model, added rules too. But value for that field "sell_price_default" is not being saved in DB. can anyone guide me what i am missing. below is my model
<?php
namespace app\models;
use Yii;
use yii\web\UploadedFile;
/**
* This is the model class for table "food".
*
* @property integer $food_id
* @property string $short_desp
* @property string $long_desp
* @property string $image_url
* @property integer $fc_id
* @property string $sell_price_default
*/
class Food extends \yii\db\ActiveRecord
{
/**
* @var UploadedFile|Null file attribute
*/
public $file;
/**
* @var selling price default value.
*/
public $sell_price_default;
const SCENARIO_ADD = 'add_food';
const SCENARIO_EDIT = 'edit_food';
/**
* @inheritdoc
*/
public static function tableName()
{
return 'foods';
}
public function scenarios()
{
$scenarios = parent::scenarios();
$scenarios[self::SCENARIO_ADD] = ['fc_id', 'short_desp', 'long_desp', 'file', 'sell_price_default'];
$scenarios[self::SCENARIO_EDIT] = ['short_desp', 'long_desp', 'fc_id', 'sell_price_default'];
return $scenarios;
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['sell_price_default'], 'string'],
[['short_desp', 'long_desp', 'fc_id', 'image_url', 'sell_price_default' ], 'required', 'on' => self::SCENARIO_ADD],
[['short_desp', 'long_desp', 'fc_id', 'image_url', 'sell_price_default'], 'required', 'on' => self::SCENARIO_EDIT],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'food_id' => 'Food ID',
'short_desp' => 'Short Desp',
'long_desp' => 'Long Desp',
'image_url' => 'Image Url',
'fc_id' => 'Fc ID',
'sell_price_default' => 'Default Selling Price'
];
}
}