function save($object = '', $related_field = '') { if (!$this->exists() || empty($this->code)) { $o = new article(); $o->select_max('position'); $o->get(); if (count($o->all) != 0) { $max = $o->position + 1; $this->position = $max; } else { $this->postion = 1; } $position = (string) $this->position; $l = 5 - strlen($position); $st = ""; for ($i = 0; $i < $l; $i++) { $st .= "0"; } $position = $st . $position; $this->code = "NEWS" . $position; } return parent::save($object, $related_field); }