Fetch Username based in user_id

Fuhrmann

Well-known member
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!
 
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);
			}
 
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.
 
Top Bottom