function updatePosition() { $positionList = $this->input->post('positionList'); $idList = $this->input->post('idList'); $locations = new Province(); for ($i = 0; $i < count($idList); $i++) { $locations->where("id", $idList[$i]); $locations->get(); $locations->position = $positionList[$i]; $locations->save(); $locations->clear(); } redirect("admin/locations/listAll/"); }
function save($object = '', $related_field = '') { if (!$this->exists()) { $o = new Province(); $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); }