/** * Finds the Student model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Student the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findStudentModel($id) { $student = Student::findOne($id); if (!isset($student)) { throw new NotFoundHttpException('The requested page does not exist.'); } return $student; }
public function actionUpdateStudent($studentId) { $student = Student::findOne($studentId); $studentAppointment = null; if (empty($student->studentAppointments)) { $studentAppointment = new StudentAppointment(); $studentAppointment->student_id = $studentId; } else { $studentAppointment = $student->studentAppointments[0]; } if (!isset($student)) { throw new HttpException(404, 'The requested page does not exist.'); } if ($student->load(Yii::$app->request->post()) && $student->save() && $studentAppointment->load(Yii::$app->request->post()) && $studentAppointment->save()) { if ($student->avatarManager->isImageSavedToDiskOk) { Yii::$app->session->setFlash('info', Yii::t('app', "{$student} updated successfully")); } else { Yii::$app->session->setFlash('info', Yii::t('app', 'There was some error uploading your avatar Image')); } return $this->redirect(['default/list-students']); } return $this->render('update-student', compact('student', 'studentAppointment')); }
/** * Finds the Student model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Student the loaded model * @throws HttpException if the model cannot be found */ protected function findModel($id) { if (($model = Student::findOne($id)) !== null) { return $model; } else { throw new HttpException(404, 'The requested page does not exist.'); } }
public function getIsStudent() { if (Student::findOne(['user_id' => $this->id])) { return true; } else { return false; } }
/** * @inheritdoc * Удаляем связанную дисциплину, если не осталось для нее записи с именем */ public function afterDelete() { if (!static::find()->where(['id_student' => $this->id_student_cached])->exists()) { Student::findOne($this->id_student_cached)->delete(); } }