Jump to main content Jump to doc navigation

modX::getUser

Get the current authenticated User and assigns it to the modX instance.

Syntax

API Doc: http://api.modx.com/revolution/2.2/db_core_model_modx_modx.class.html#%5CmodX::getUser()

modUser getUser ([string $contextKey = ''])

Example

Get the current auth'ed user and print out its username.

$user = $modx->getUser();
echo $user->get('username');

Get the user's email address (stored in their profile):

$user = $modx->getUser();
if (!$user) return '';
$profile = $user->getOne('Profile');
if (!$profile) return '';
print $profile->get('email');

Get an extended field from the user.

$user = $modx->getUser();
if (!$user) return '';
$profile = $user->getOne('Profile');
if (!$profile) return '';
$extended = $profile->get('extended');
print (isset($extended['custom_user_field'])) ? $extended['custom_user_field'] : '';

See Also