public function action_edit($id = null) { is_null($id) and Response::redirect('Survey_Question'); if (!($survey_question = Model_Survey_Question::find($id))) { Session::set_flash('error', 'Could not find survey_question #' . $id); Response::redirect('Survey_Question'); } $val = Model_Survey_Question::validate('edit'); if ($val->run()) { $survey_question->survey_id = Input::post('survey_id'); $survey_question->question = Input::post('question'); if ($survey_question->save()) { Session::set_flash('success', 'Updated survey_question #' . $id); Response::redirect('survey/question'); } else { Session::set_flash('error', 'Could not update survey_question #' . $id); } } else { if (Input::method() == 'POST') { $survey_question->survey_id = $val->validated('survey_id'); $survey_question->question = $val->validated('question'); Session::set_flash('error', $val->error()); } $this->template->set_global('survey_question', $survey_question, false); } $this->template->title = "Survey_questions"; $this->template->content = View::forge('survey/question/edit'); }