Wednesday, November 17, 2010

Modx 2 getUser

Instead of calling $modx->getUser to get currently logged in user,
use getAuthenticatedUser.

$oUser = $modx->getAuthenticatedUser($modx->context->get("key"));
echo $oUser->username;
echo $oUser->getOne("Profile")->fullname;

If you use "getUser", it might return the first user in the database if the person is not logged in, which might not be what you are looking for.

hope it helps :)

No comments: