save() абстрактный публичный Метод

If the ID field can vary, consult $model->id_field. You do not have to worry about default fileds, because their values will automatically be in $data. If $id is null then new record must be created. If $id is specified, then record must be overwritten. Method must return $id of stored record. This method may throw exceptions.
abstract public save ( $model, $id, $data )
Пример #1
0
 /**
  * Saves record with current controller. Uses $this->id as primary key.
  * If not set, new record is created.
  */
 public function save()
 {
     $this->hook('beforeSave', array($this->id));
     $is_update = $this->loaded();
     if ($is_update) {
         $source = array();
         foreach ($this->dirty as $name => $junk) {
             $source[$name] = $this->get($name);
         }
         // No save needed, nothing was changed
         if (empty($source)) {
             return $this;
         }
         $this->hook('beforeUpdate', array(&$source));
     } else {
         // Collect all data of a new record
         $source = $this->get();
         $this->hook('beforeInsert', array(&$source));
     }
     if ($this->controller) {
         $this->id = $this->controller->save($this, $this->id, $source);
     }
     if ($is_update) {
         $this->hook('afterUpdate');
     } else {
         $this->hook('afterInsert');
     }
     if ($this->loaded()) {
         $this->dirty = array();
         $this->hook('afterSave', array($this->id));
     }
     return $this;
 }