yii\base\Model::getAttributes PHP Method

getAttributes() public method

Returns attribute values.
public getAttributes ( array $names = null, array $except = [] ) : array
$names array list of attributes whose value needs to be returned. Defaults to null, meaning all attributes listed in [[attributes()]] will be returned. If it is an array, only the attributes in the array will be returned.
$except array list of attributes whose value should NOT be returned.
return array attribute values (name => value).
    public function getAttributes($names = null, $except = [])
    {
        $values = [];
        if ($names === null) {
            $names = $this->attributes();
        }
        foreach ($names as $name) {
            $values[$name] = $this->{$name};
        }
        foreach ($except as $name) {
            unset($values[$name]);
        }
        return $values;
    }

Usage Example

Example #1
1
 /**
  * @param $values
  * @param Model $model
  */
 protected function getAttributes(&$values, Model $model)
 {
     foreach ($model->getAttributes() as $attribute => $value) {
         $className = explode('\\', get_class($model));
         $className = $className[count($className) - 1];
         $values[$this->getKeyFromAttribute($className, $attribute)] = $value;
     }
 }
All Usage Examples Of yii\base\Model::getAttributes