function save($object = '', $related_field = '') { if (!$this->exists()) { $o = new Estateward(); $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 getWard() { $districtId = $this->input->post('districtId'); $wards = new Estateward(); $wards->where('estatedistrict_id', $districtId); $wards->order_by('position', 'asc'); $wards->get(); $option = '<option value="" selected="">Chọn Xã/Phường</option>'; foreach ($wards as $row) { if ($row->id == $this->input->post('wardSelected')) { $option .= '<option selected="selected" value=' . $row->id . '>' . $row->name . '</option>'; } else { $option .= '<option value=' . $row->id . '>' . $row->name . '</option>'; } } echo $option; die; }