XF 2.1 Correct way to grab all properties of an XF Entity?

So I'm pretty new to XF, so I'm not sure if this is a basic question. But basically, I'm writing some third-party software that is extending some of the classes as such from XF so that I can link forum accounts with my software. At the moment, I'm very much in WIP phase but I've run into a bit of an issue;

Code:
$user = XF::visitor();

This returns a User class instance and I'm able to use getters such as; $user->email, etc... However, is there any way for me to just output the full array without using getters? E.G
Code:
[
    "user_id" => 1
    "username" => "test"
    "email" => "test@localhost.local"
    "custom_title" => ""
    "language_id" => 0
    "style_id" => 0
    "timezone" => "Europe/London"
    "visible" => 1
    "activity_visible" => 1
    "user_group_id" => 2
    "secondary_group_ids" => "3,4"
    "display_style_group_id" => 3
    "permission_combination_id" => 6
    "message_count" => 0
    "conversations_unread" => 0
    "register_date" => 1561485512
    "last_activity" => 1564498857
    "trophy_points" => 0
    "alerts_unread" => 0
    "avatar_date" => 0
    "avatar_width" => 0
    "avatar_height" => 0
    "avatar_highdpi" => 0
    "gravatar" => ""
    "user_state" => "valid"
    "is_moderator" => 1
    "is_admin" => 1
    "is_banned" => 0
    "reaction_score" => 0
    "warning_points" => 0
    "is_staff" => 1
    "secret_key" => "123"
    "privacy_policy_accepted" => 0
    "terms_accepted" => 0
  ]

Because as of currently, if I try and return or json_encode this instance in any way, I just get and empty object/array like so;
Code:
"{}"

I tried searching myself for some sort of getter function but can't seem to find anything.
I also have similar issues using the finder where whenever I try and return, it just returns an empty array/object.

Hopefully someone can provide some insight.
 
The Entity::toArray() method can do this, though it is discouraged to store the contents of a user entity. It might be better to store the user identifier, and manually fetch the user record, unless you’re keeping them in sync.
 
You can use the fetchRaw method for this.
The Entity::toArray() method can do this, though it is discouraged to store the contents of a user entity. It might be better to store the user identifier, and manually fetch the user record, unless you’re keeping them in sync.
Try searching harder ;)

\XF\Mvc\Entity\Entity::toArray()

Damn, @Liam W was faster, already had teh reply wirttten a couple minutes ago but was AFK afterwards.

Wow! Can't believe it was that simple. Guess I definitely wasn't looking hard enough! Thanks a lot for all the help. :)
 
Back
Top Bottom