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

Getting UserID From UserName

Discussion in 'XenForo Development Discussions' started by TheBigK, Apr 22, 2015.

  1. TheBigK

    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:

    $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.
  2. Daniel Hood

    Daniel Hood Well-Known Member

    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).
    TheBigK likes this.
  3. TheBigK

    TheBigK Well-Known Member

    Thanks, Daniel. I think I'm already doing that - but not sure the right way:

    Here's my input box:
    <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: Apr 22, 2015
  4. Daniel Hood

    Daniel Hood Well-Known Member

    Look at other places it's used. Like the search controller.

Share This Page