public function action_edit($id = null) { $student = Model_Student::find('first', ['where' => ['user_id' => $id]]); if (!$student) { $student = Model_Student::forge(['user_id' => $id]); } $val = Model_Student::validate('edit'); if ($val->run()) { $student->user_id = Input::post('user_id'); $student->year_level = Input::post('year_level'); $student->course_id = Input::post('course_id'); if ($student->save()) { Session::set_flash('success', e('Updated student #' . $id)); Response::redirect('site/student'); } else { Session::set_flash('error', e('Could not update student #' . $id)); } } else { if (Input::method() == 'POST') { $student->user_id = $val->validated('user_id'); $student->year_level = $val->validated('year_level'); $student->course_id = $val->validated('course_id'); Session::set_flash('error', $val->error()); } $this->template->set_global('student', $student, false); } $this->template->title = "Students"; $this->template->content = View::forge('site/student/edit'); }