public function create() { $this->load->library('form_validation'); $this->form_validation->set_rules('period[name]', 'lang:admin_periods_form_field_name', 'required|is_unique[periods.name]'); if ($this->form_validation->run()) { $this->_transaction_isolation(); $this->db->trans_begin(); $periods = new Period(); $periods->update('sorting', 'sorting + 1', FALSE); $period_data = $this->input->post('period'); $period = new Period(); $period->from_array($period_data, array('name')); $period->sorting = 1; if ($period->save() && $this->db->trans_status()) { $this->db->trans_commit(); $this->messages->add_message('lang:admin_periods_flash_message_save_successful', Messages::MESSAGE_TYPE_SUCCESS); $this->_action_success(); } else { $this->db->trans_rollback(); $this->messages->add_message('lang:admin_periods_flash_message_save_failed', Messages::MESSAGE_TYPE_ERROR); } redirect(create_internal_url('admin_periods/new_period_form')); } else { $this->new_period_form(); } }