Extending user model only working for $visitor

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:
PHP:
<?php
 
class HtmlUserNames_Model_User extends XFCP_HtmlUserNames_Model_User
{
public function prepareUserFetchOptions(array $fetchOptions)
{
$parent = parent::prepareUserFetchOptions($fetchOptions);
 
$parent['selectFields'] .= ',
xf_user_hun.*';
$parent['joinTables'] .= '
LEFT JOIN xf_user_hun ON (user.user_id = xf_user_hun.user_id)';
 
return $parent;
}
 
}
 
For testing the message_user_info.

Otherwise I need it in every template where username or user's title is is displayed.
 
For post related templates, you will need to extend the Model/Post.php preparePostJoinOptions() function
 
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.
 
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?
 
New problem, for some reason all users on the Members page is showing up as guests.
 
New problem, for some reason all users on the Members page is showing up as guests.
I ran into a similar predicament and here is my solution:
HTML:
<?php

class HtmlUserNames_Model_Post extends XFCP_HtmlUserNames_Model_Post
{
    public function preparePostJoinOptions(array $fetchOptions)
    {
        $parent = parent::preparePostJoinOptions($fetchOptions);

        $parent['selectFields'] .= ',
            xf_user_hun.*';
        $parent['joinTables'] .= '
            LEFT JOIN xf_user_hun ON (post.user_id = xf_user_hun.user_id)';

        return $parent;
    }
}
 
Last edited:
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?
 
Top Bottom