1. 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

Discussion in 'XenForo Development Discussions' started by Fuhrmann, Oct 2, 2011.

  1. Fuhrmann

    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!
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

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

    Fuhrmann Well-Known Member

    Thanks! That really helped me.
     

Share This Page