• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Fetch Username based in user_id

Fuhrmann

Well-known member
#1
Hello, first sorry for my bad english.

I am making my first addon and I created a field in the database (xf_thread) called who_locked receiving a user ID.

I created a template (who_locked_bit) and want to use this value in order to present the user name based on the id.

Is there any way to do this?

Thanks in advance!
 

Jake Bunce

XenForo moderator
Staff member
#2
I would use the user model:

XenForo_Model_User::getUserById

Simply pass the userid into this function and it will return the user record.

You can see examples in the other controllers. For example:

XenForo_ControllerPublic_Account::actionFollow

PHP:
		$userModel = $this->_getUserModel();

		if (!empty($input['user_id']))
		{
			if (!$user = $userModel->getUserById($input['user_id']))
			{
				return $this->responseError(new XenForo_Phrase('requested_member_not_found'), 404);
			}
 

Fuhrmann

Well-known member
#3
I would use the user model:

XenForo_Model_User::getUserById

Simply pass the userid into this function and it will return the user record.

You can see examples in the other controllers. For example:

XenForo_ControllerPublic_Account::actionFollow

PHP:
$userModel = $this->_getUserModel();

if (!empty($input['user_id']))
{
if (!$user = $userModel->getUserById($input['user_id']))
{
return $this->responseError(new XenForo_Phrase('requested_member_not_found'), 404);
}
Thanks! That really helped me.