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

Extending user model only working for $visitor

Discussion in 'XenForo Development Discussions' started by MOZ, Feb 26, 2013.

  1. MOZ

    MOZ Well-Known Member

    I've extended the user model to join some columns from another column. Issue is the value from these columns is only accessed when $visitor is used.

    Eg, If I use this: {$visitor.HUN_username_styling} it shows the value
    but if I use this: {$user.HUN_username_styling} it doesn't show anything

    And yes the $user variable is available.

    Here is how I am extending the user model:
    class HtmlUserNames_Model_User extends XFCP_HtmlUserNames_Model_User
    public function 
    prepareUserFetchOptions(array $fetchOptions)
    $parent parent::prepareUserFetchOptions($fetchOptions);
    $parent['selectFields'] .= ',
    $parent['joinTables'] .= '
    LEFT JOIN xf_user_hun ON (user.user_id = xf_user_hun.user_id)'
  2. Syndol

    Syndol Guest

    Which template are you calling the $user array from?
  3. MOZ

    MOZ Well-Known Member

    For testing the message_user_info.

    Otherwise I need it in every template where username or user's title is is displayed.
  4. Syndol

    Syndol Guest

    For post related templates, you will need to extend the Model/Post.php preparePostJoinOptions() function
  5. MOZ

    MOZ Well-Known Member

    But I need the variable available wherever the $user variable is available.

    If I add a column to the xf_user table, then the column is always available to be called from the $user variable, similarly, I want the same functionality, but without adding the columns to xf_user, and from another table.

    I hope this clears the problem a little better.
  6. MOZ

    MOZ Well-Known Member

    Is there a way to "attach" columns from another table to xf_user so their values are available everywhere (Wherever $user is available) like the columns of xf_user?
  7. MOZ

    MOZ Well-Known Member

    New problem, for some reason all users on the Members page is showing up as guests.
  8. silence

    silence Well-Known Member

    I ran into a similar predicament and here is my solution:
    class HtmlUserNames_Model_Post extends XFCP_HtmlUserNames_Model_Post
        public function preparePostJoinOptions(array $fetchOptions)
            $parent = parent::preparePostJoinOptions($fetchOptions);
            $parent['selectFields'] .= ',
            $parent['joinTables'] .= '
                LEFT JOIN xf_user_hun ON (post.user_id = xf_user_hun.user_id)';
            return $parent;
    Last edited: Sep 29, 2013
  9. tyteen4a03

    tyteen4a03 Well-Known Member

    Given that you are extending XF_Model_User, I can't seem to find this function anywhere. I can only find prepareUserFetchOptions. Is that what you mean?
  10. Nobita.Kun

    Nobita.Kun Well-Known Member

    I think that is XenForo_Model_Post :D
  11. silence

    silence Well-Known Member

    Oops I forgot to fix that. Post updated!

Share This Page