User objects carry a lot of information with them, including the user's username, e-mail, and several other attributes. In this recipe, we will run through several functions to retrieve data associated with users.
The code for this chapter doesn't necessarily belong to any specific place in concrete5. The steps for this recipe are basic, one-line functions to demonstrate the different ways to get data from a user object. If you'd like a place to just write arbitrary code and have concrete5 evaluate it, the site_post.php
file in config/
is a pretty good place to start.
The steps for getting a user's info are as follows:
First, we will load the currently logged-in user.
$user = new User();
Get the user's ID.
$userId = $user->getUserID();
Get the user's username.
$username = $user->getUserName();
Check if the user is registered on the site.
$isRegistered = $user->isRegistered();
Check if the user's account is active.
$isActive = $user->isActive...