public function action_edit($id = null) { is_null($id) and Response::redirect('department'); if (!($department = Model_Department::find($id))) { Session::set_flash('error', 'Could not find department #' . $id); Response::redirect('department'); } $val = Model_Department::validate('edit'); if ($val->run()) { $department->name = Input::post('name'); $department->phone = Input::post('phone'); $department->email = Input::post('email'); $department->hotline = Input::post('hotline'); $department->address = Input::post('address'); if ($department->save()) { Session::set_flash('success', 'Updated department #' . $id); Response::redirect('department'); } else { Session::set_flash('error', 'Could not update department #' . $id); } } else { if (Input::method() == 'POST') { $department->name = $val->validated('name'); $department->phone = $val->validated('phone'); $department->email = $val->validated('email'); $department->hotline = $val->validated('hotline'); $department->address = $val->validated('address'); Session::set_flash('error', $val->error()); } $this->template->set_global('department', $department, false); } $this->template->title = "Departments"; $this->template->content = View::forge('department/edit'); }