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