* Sets the attribute values in a massive way. * @param array $values attribute values (name => value) to be assigned to the model. * @param bool $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 [[scenario]]. * @see safeAttributes() * @see attributes() */
($values, $safeOnly = true)
| 734 | * @see attributes() |
| 735 | */ |
| 736 | public function setAttributes($values, $safeOnly = true) |
| 737 | { |
| 738 | if (is_array($values)) { |
| 739 | $attributes = array_flip($safeOnly ? $this->safeAttributes() : $this->attributes()); |
| 740 | foreach ($values as $name => $value) { |
| 741 | if (isset($attributes[$name])) { |
| 742 | $this->$name = $value; |
| 743 | } elseif ($safeOnly) { |
| 744 | $this->onUnsafeAttribute($name, $value); |
| 745 | } |
| 746 | } |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | /** |
| 751 | * This method is invoked when an unsafe attribute is being massively assigned. |
no test coverage detected