Getting UserID From UserName

TheBigK

Well-known member
I'm trying to get the UserID of a user whose username is known. For example, in my code, I've this:

PHP:
$receiverUserName= $this->_input->filterSingle('username', XenForo_Input::STRING);
$receiver = $this->getModelFromCache('XenForo_Model_User')->getUserByName($receiverUserName);

Using debug information, I found out that the $receiver gets the entire user array and not just the Id. What's the best way to get userID from username?

PS: I'm guessing that there'd be a ready-made function to do it in XenForo. But I do not know how / where to look for them.
 
Just get the full array. I recommend using the auto complete functionality (look at how it's done for searching posts by member) and using that instead though (as that actually submits the user id instead of username + provides auto complete functionality).
 
Just get the full array. I recommend using the auto complete functionality (look at how it's done for searching posts by member) and using that instead though (as that actually submits the user id instead of username + provides auto complete functionality).
Thanks, Daniel. I think I'm already doing that - but not sure the right way:

Here's my input box:
PHP:
<xen:textboxunit name="username" label="Send To:" inputclass="AutoComplete AcSingle" value="{$visitor.username}" />

Do I need to make any change to this -

$receiverUserName = $this->_input->filterSingle('username', XenForo_Input::STRING); ?

Because the it sets the $receiverUserName to the user name I'm typing in the box.

Update: Wondering if something like:
$receiverUserName = XenForo_Input::UINT would work. Gotta check.
 
Last edited:
Back
Top Bottom