Exemple #1
0
 /**
  * Sets the attribute values in a massive way.
  * @param array $values attribute values (name=>value) to be set.
  * @param boolean $safeOnly 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 {@link scenario}.
  * @see getSafeAttributeNames
  * @see attributeNames
  * @since v1.3.1
  */
 public function setAttributes($values, $safeOnly = true)
 {
     if (!is_array($values)) {
         return;
     }
     if ($this->hasEmbeddedDocuments()) {
         $attributes = array_flip($safeOnly ? $this->getSafeAttributeNames() : $this->attributeNames());
         foreach ($this->embeddedDocuments() as $fieldName => $className) {
             if (isset($values[$fieldName]) && isset($attributes[$fieldName])) {
                 $this->{$fieldName}->setAttributes($values[$fieldName], $safeOnly);
                 unset($values[$fieldName]);
             }
         }
     }
     parent::setAttributes($values, $safeOnly);
 }