yii\base\Model::attributes PHP Method

attributes() public method

By default, this method returns all public non-static properties of the class. You may override this method to change the default behavior.
public attributes ( ) : array
return array list of attribute names.
    public function attributes()
    {
        $class = new ReflectionClass($this);
        $names = [];
        foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
            if (!$property->isStatic()) {
                $names[] = $property->getName();
            }
        }
        return $names;
    }

Usage Example

Example #1
0
 /**
  * Overrides default [[attributes()]] method.
  * Extracts attributes from the validation rules described in [[rules()]] method.
  *
  * @return array
  */
 public function attributes()
 {
     $attributes = \yii\base\Model::attributes();
     foreach (self::rules() as $rule) {
         if (is_string(reset($rule))) {
             continue;
         }
         foreach (reset($rule) as $attribute) {
             if (substr_compare($attribute, '!', 0, 1) === 0) {
                 $attribute = mb_substr($attribute, 1);
             }
             $attributes[$attribute] = $attribute;
         }
     }
     return array_values($attributes);
 }
All Usage Examples Of yii\base\Model::attributes