8.4.2 How to get user name?

Permalink
I'm trying to get a user name. If I use UserInfo, all works fine, but as it's deprecated, when I use getUserInfoObject, it throws an error: "Call to a member function getByID() on null".

Here's the controller's view():
$this->set('u', new User());

Here's the view.php:
$ui = $u->getUserInfoObject();
echo $ui->getByID($comment->getUID())->getUserName();

This works:
echo \UserInfo::getByID($comment->getUID())->getUserName();

What am I missing with the getUserInfoObject?

linuxoid
 
linuxoid replied on at Permalink Reply
linuxoid
Got it!
echo $u->getByUserID($comment->getUID())->getUserName();

The UserInfoObject is not even required.