I am getting a problem while saving a form in yii2.
I have created a custom field with name like other fields Myposts['categoryLevel2']. This field is not in model. It is a conditional field. When I post my from I assign its value to a model attribute Like:
$categoryLevel3 = $request->post('categoryLevel3');
if(!empty($categoryLevel3)){
$model->category=$categoryLevel3;
}
Now because categoryLevel3 is not there in table post so it is giving error.
Getting unknown property: frontend\models\Posts
I know the issue. The error is because in $_POST array there is a field categoryLevel3 now and it is not in table so $model->save() is throwing exception. I tried unset($_POST['categoryLevel3')) but that also did not work. Can anyone help me on this?
How can I create a filed in view which is not in table and ignore it before $model->save?
Add Public property 'categoryLevel3 in Your Post Model Class.
class Post extends yii\db\ActiveRecord{
public $categoryLevel3;
public function rules(){
return [
[''categoryLevel3' , 'required']
...
];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With