1

I was wondering if there is a way to get just the attributes name? In the example I mean: id, name, user. I don´t need the values, just name of attributes.

app\models\Data Object
(
[_attributes:yii\db\BaseActiveRecord:private] => Array
    (
        [id] => 1
        [name] => 
        [user] => 
    )

[_oldAttributes:yii\db\BaseActiveRecord:private] => Array
    (
        [id] => 1
        [name] => 
        [user] =>             
    )    
)

Thanks!

2
  • 3
    array_keys($model->attributes); Commented Oct 27, 2016 at 16:27
  • @Bizley Great! Thank you! Commented Oct 27, 2016 at 16:40

1 Answer 1

8

You can do it like the code in the comment but Yii also provides a function on ActiveRecord itself to get the attribute names:

$model->attributes();

Official docs: http://www.yiiframework.com/doc-2.0/yii-db-activerecord.html#attributes()-detail

Sign up to request clarification or add additional context in comments.

1 Comment

Excellente, both options do it! Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.