function save($object = '', $related_field = '') { if (!$this->exists()) { $o = new configgroup(); $o->select_max('position'); $o->get(); if (count($o->all) != 0) { $max = $o->position + 1; $this->position = $max; } else { $this->postion = 1; } } return parent::save($object, $related_field); }
function edit() { $cauhinh_id = $this->uri->segment(4); //if request is GET $cauhinh = new cauhinh($cauhinh_id); if ($_SERVER['REQUEST_METHOD'] == "GET") { //do no-thing } else { $rel = $cauhinh->from_array($_POST, array('name', 'fieldname', 'description', 'configgroup', 'type', 'choice_list', 'for_webmaster', 'check_for_update', 'style')); if ($cauhinh->save($rel)) { redirect($this->admin . 'cauhinhs/edit/' . $cauhinh_id); } } $configgroup = new configgroup(); $configgroup->order_by('position', 'asc'); $configgroup->get(); $dis['configgroup'] = $configgroup; $dis['base_url'] = base_url(); $dis['menu_active'] = "Cấu hình hệ thống"; $dis['title'] = "Sửa thông tin cấu hình"; $dis['object'] = $cauhinh; $dis['view'] = 'cauhinh/edit'; $dis['nav_menu'] = array(array("type" => "back", "text" => "Quay lại", "link" => "{$this->admin_url}cauhinhs/", "onclick" => "")); $this->viewadmin($dis); }