Here is my model rules
public function rules() {
return [
[['header_image', 'profil_picture'], 'default', 'value' => null],
[['yahoo_id', 'whats_app_id', 'bbm_id'], 'string', 'max' => 20],
[['bbm_id'], 'match', 'pattern' => '/^[a-zA-Z0-9]+$/', 'message' => 'Alpha numeric only'],
[['header_image_file', 'profil_picture_file'], 'file', 'skipOnEmpty' => true, 'extensions' => 'png, jpeg, jpg, bmp', 'maxSize' => 10240 * 20240 * 2],
[['deskripsi_toko'], 'string', 'max' => 300],
[['agent_id', 'nama_toko', 'tag_line', 'header_image', 'profil_picture', 'yahoo_id', 'whats_app_id', 'bbm_id', 'deskripsi_toko'], 'filter', 'filter' => function($value) {
return BeoHelper::replace_mc($value);
}],
];
}
Here is my controller
$storeSetting->header_image = null;
if($storeSetting->save()){
return $this->redirect(Yii::$app->request->referrer);
}
replace_mc function
public static function replace_mc($str)
{
$new_data = preg_replace('/[^A-Za-z0-9\-\ \.\:\@\+]/', '', $str);
return $new_data;
}
Record save successfully, but header_image
is empty string instead of null?
It should set header_image
as null, Where I'm doing wrong?
Thanks in advance.