/** * Creates a new Main model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Main(); if ($model->load(Yii::$app->request->post())) { // Load time_array manually, since it's not part of Main Table $model->time_array = Yii::$app->request->post()['Main']['time_array']; // Convert array to bit $model->time_bit = $model->encodeBit($model->time_array); // Add Owner $model->user_id = Yii::$app->user->identity->id; $model->created = date('Y-m-d H:i:s'); $model->updated = date('Y-m-d H:i:s'); // Force null $model->drug_name = empty($model->drug_name) ? null : $model->drug_name; if ($model->save()) { Yii::$app->getSession()->setFlash('main_create_success', ['type' => Growl::TYPE_SUCCESS, 'title' => '<b>' . Yii::t('backend', 'Success') . '</b>', 'icon' => 'glyphicon glyphicon-ok-sign', 'body' => '<strong>' . $model->profile_name . '</strong> ' . Yii::t('backend', 'has been added.')]); return $this->redirect(['index']); } } return $this->render('create', ['model' => $model]); }