/** * Creates a new Student model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Student(); try { if ($model->load($_POST) && $model->save()) { return $this->redirect(Url::previous()); } elseif (!\Yii::$app->request->isPost) { $model->load($_GET); } } catch (\Exception $e) { $msg = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage(); $model->addError('_exception', $msg); } return $this->render('create', ['model' => $model]); }
/** * Creates a new Student model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $student = new Student(); $post = Yii::$app->request->post(); if ($student->load($post) && $student->save()) { return $this->redirect(['index']); } return $this->render('create', compact('student')); }
/** * Creates a new Student model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Student(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['manage']); } else { return $this->renderAjax('create', ['model' => $model]); } }
public function actionCreateStudent() { $student = new Student(); $studentAppointment = new StudentAppointment(); $student->user_id = Yii::$app->user->id; if ($student->load(Yii::$app->request->post()) && $student->validate()) { $student->save(); $studentAppointment->student_id = $student->id; if ($studentAppointment->load(Yii::$app->request->post()) && $studentAppointment->validate()) { $studentAppointment->save(); Yii::$app->session->setFlash('info', "{$student} created successfully"); return $this->redirect(['default/list-students']); } } return $this->render('create-student', compact('student', 'studentAppointment')); }
/** * Новая модель student и связанная с ней новая модель student_education * @return mixed */ public function actionCreate($idParent = null) { /* @var $student Student */ /* @var $studentEducation StudentEducation */ $student = new Student(); $studentEducation = new StudentEducation(); $studentEducation->id_program = $idParent; if ($student->load(Yii::$app->request->post()) && $student->save()) { $studentEducation->load(Yii::$app->request->post()); $studentEducation->id_student = $student->id; $studentEducation->year = YearHelper::getYear(); $studentEducation->save(); return 'Item is succesfully created.'; // alert message } else { return $this->renderAjax('update', ['student' => $student, 'studentEducation' => $studentEducation]); } }