コード例 #1
0
 public function actionProfile($params = [])
 {
     if (Student::isAuthorized()) {
         $student = new Student();
         $student->loadModelFromDb(['email' => $_COOKIE['email']]);
         if (isset($_POST) && !empty($_POST)) {
             // TODO: validate user input
             // TODO: replace 'on' value in $_POST["local"]
             $student->fetchSchema();
             foreach ($_POST as $key => $attribute) {
                 if ($student->{$key} !== $attribute) {
                     $student->modifiedAttributes[$key] = $attribute;
                 }
             }
             if (!empty($student->modifiedAttributes)) {
                 $student->update();
             }
         }
         $this->render('profile.php', ['student' => $student]);
     } else {
         Router::error('403');
     }
 }