function save() { $work = new Work(); $work->staff_id = $this->staff_id; $work->history_date = $this->input->post('history_date'); $work->history_description = $this->input->post('history_description'); if ($work->save()) { $this->session->set_flashdata('message', 'Work successfully created!'); redirect('staffs/' . $this->staff_id . '/work_histories/index'); } else { // Failed $work->error_message('custom', 'Field required'); $msg = $work->error->custom; $this->session->set_flashdata('message', $msg); redirect('staffs/' . $this->staff_id . '/work_histories/add'); } }