yii\base\Model::setAttributes PHP Метод

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

Sets the attribute values in a massive way.
См. также: safeAttributes()
См. также: attributes()
public setAttributes ( array $values, boolean $safeOnly = true )
$values array attribute values (name => value) to be assigned to the model.
$safeOnly boolean whether the assignments should only be done to the safe attributes. A safe attribute is one that is associated with a validation rule in the current [[scenario]].
    public function setAttributes($values, $safeOnly = true)
    {
        if (is_array($values)) {
            $attributes = array_flip($safeOnly ? $this->safeAttributes() : $this->attributes());
            foreach ($values as $name => $value) {
                if (isset($attributes[$name])) {
                    $this->{$name} = $value;
                } elseif ($safeOnly) {
                    $this->onUnsafeAttribute($name, $value);
                }
            }
        }
    }

Usage Example

Пример #1
0
 /**
  * @inheritdoc
  */
 public function setAttributes($values, $safeOnly = true)
 {
     parent::setAttributes($values, $safeOnly);
     if (empty($this->images)) {
         $this->images = [];
     }
 }
All Usage Examples Of yii\base\Model::setAttributes