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

This method will call [[insert()]] when [[isNewRecord]] is true, or BaseActiveRecord::update when [[isNewRecord]] is false. For example, to save a customer record: php $customer = new Customer; // or $customer = Customer::findOne($id); $customer->name = $name; $customer->email = $email; $customer->save();
public save ( boolean $runValidation = true, array $attributeNames = null ) : boolean
$runValidation boolean whether to perform validation (calling [[validate()]]) before saving the record. Defaults to `true`. If the validation fails, the record will not be saved to the database and this method will return `false`.
$attributeNames array list of attribute names that need to be saved. Defaults to null, meaning all attributes that are loaded from DB will be saved.
Результат boolean whether the saving succeeded (i.e. no validation errors occurred).
Пример #1
0
 /**
  * 
  * @param \yii\base\Event $event
  */
 public function afterSave($event)
 {
     foreach ($this->relationKey as $from => $to) {
         $this->_relation[$to] = $this->owner[$from];
     }
     $this->_relation->save();
 }
Пример #2
0
 /**
  * Saves the current record.
  */
 public function save($runValidation = true, $attributeNames = null)
 {
     return parent::save($runValidation, $attributeNames);
 }