public function actionCreate() { $model = new Minor(); $model->setScenario('create'); if ($model->load(Yii::$app->session->get('create'), '') && $model->load(Yii::$app->request->post()) && isset($model->fin) && $model->save()) { Yii::$app->session->setFlash('Success'); Yii::$app->session->remove('create'); return $this->render('create'); } else { if ($model->load(Yii::$app->request->post()) && $model->validate()) { if (!Yii::$app->request->get('status')) { Yii::$app->session->remove('create'); } Yii::$app->session->setFlash('step2'); Yii::$app->session->set('create', $model->attributes); return $this->render('create', ['model' => $model]); } else { if (!Yii::$app->request->get('status')) { Yii::$app->session->remove('create'); } $model->load(Yii::$app->session->get('create'), ''); Yii::$app->session->setFlash('step1'); return $this->render('create', ['model' => $model]); } } }
public function actionMinor() { Yii::$app->response->format = Response::FORMAT_JSON; $userId = Yii::$app->request->post('user_id1'); $full_name = Yii::$app->request->post('full_name'); $full_child_name = Yii::$app->request->post('full_child_name'); $child_dob = Yii::$app->request->post('child_dob'); $printed_name = Yii::$app->request->post('printed_name'); $contact_info = Yii::$app->request->post('contact_info'); $signature = Yii::$app->request->post('image'); $dirPath = 'images/' . $userId; $filePath = $dirPath . '/' . uniqid() . '_' . $full_name . '.jpg'; FileHelper::createDirectory($dirPath); $source = imagecreatefromstring(base64_decode($_POST['image'])); imagejpeg($source, $filePath); imagedestroy($source); $model = new Minor(); $model->full_name = $full_name; $model->full_child_name = $full_child_name; $model->child_dob = $child_dob; $model->printed_name = $printed_name; $model->contact_info = $contact_info; $model->signature = $filePath; // $model->child_dob = date('U', strtotime($child_dob)); $name = Minor::find()->where(['full_name' => $full_name])->one(); if ($name) { return ['status' => 'error', 'error' => array('login' => 'Record ' . $name . ' has already been added.')]; } elseif ($model->save()) { return ['status' => 'success', 'data' => $model]; } else { return ['status' => 'error', 'data' => $model]; } }