User vs. UserInfo

When working with users in concrete5, you'll very quickly realize that there are multiple objects involved. These are

User

Found in Concrete\Core\User\User

UserInfo

Found in Concrete\Core\User\UserInfo

Distinction

Why this distinction? The User object is meant to handle just authentication, and checking whether a user is logged in. It is administrative, and isn't meant to be malleable in any way. It was also designed this way to be lighter-weight (since it might be passed around and checked fairly frequently.)

By contrast, the UserInfo object holds information about a particular user, including access to its core properties, custom attributes and more.

General Rule

Do you want to check whether the current user is logged in, log a particular user in, or check to see whether a user is part of particular group? You need the User object. Want to retrieve custom attributes or core information about a user (beyond its name and user ID)? You need the UserInfo object.

Loading Conversation