public function actionAddAjax() { if (!isset(Yii::app()->user->storeID)) { $data['message'] = '<div class="alert alert-success">Store not found. </div>'; echo json_encode($data); exit; } $model = new ServiceType(); $model->s_store_id = Yii::app()->user->storeID; if (isset($_POST['ServiceType'])) { $model->attributes = $_POST['ServiceType']; $data = array(); $mss = ''; if (count($data) == 0) { $model->pk_s_id = '-1'; $model->i_flag_sync = 1; $model->i_flag_deleted = 0; $model->i_disable = 0; if ($model->save()) { $model->pk_s_id = 'SV' . $model->id; if ($model->save()) { $data['option'] = '<option selected="selected" value ="' . $model->pk_s_id . '">' . $model->s_name . '</option>'; $data['message'] = '<div class="alert alert-success">Success! Type Service Created. </div>'; } else { $model->delete(); $data['message'] = '<div class="alert alert-danger">Error! Please try again later.</div>'; } } else { $data['message'] = json_encode($model->errors); //'<div class="alert alert-danger">Error! Please try again later2.</div>'; } } echo json_encode($data); } }