yii\db\ActiveRecordInterface::save PHP Метод

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

This method will call ActiveRecordInterface::insert when [[getIsNewRecord()|isNewRecord]] is true, or ActiveRecordInterface::update when [[getIsNewRecord()|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 [[\yii\base\Model::validate()|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).
    public function save($runValidation = true, $attributeNames = null);

Usage Example

Пример #1
0
 /**
  * @param array $link
  * @param ActiveRecordInterface $foreignModel
  * @param ActiveRecordInterface $primaryModel
  * @throws InvalidCallException
  */
 private function bindModels($link, $foreignModel, $primaryModel)
 {
     foreach ($link as $fk => $pk) {
         $value = $primaryModel->{$pk};
         if ($value === null) {
             throw new InvalidCallException('Unable to link models: the primary key of ' . get_class($primaryModel) . ' is null.');
         }
         if (is_array($foreignModel->{$fk})) {
             // relation via array valued attribute
             $foreignModel->{$fk} = array_merge($foreignModel->{$fk}, [$value]);
         } else {
             $foreignModel->{$fk} = $value;
         }
     }
     $foreignModel->save(false);
 }
All Usage Examples Of yii\db\ActiveRecordInterface::save