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

Usermodel question

Discussion in 'XenForo Development Discussions' started by Wuebit, Dec 10, 2013.

  1. Wuebit

    Wuebit Well-Known Member

    Any idea why this is not working?

    Code:
                    $userModel = XenForo_Model::create('XenForo_Model_User');
                    $identities = $userModel->getIdentities($hookParams['user']['user_id']);
    Keep getting

    Code:
    undefined method XenForo_Model_User::getIdentities()
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    "getIdentities" does not exist as a function in XenForo_Model or XenForo_Model_User.

    What are you trying to do?
     
    Wuebit likes this.
  3. Wuebit

    Wuebit Well-Known Member

    It used to work lol
    I'm just trying to pull the user ID. How do you find all the functions Chris? what would be the best way?
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    Do you not already have the user ID?
    PHP:
    $hookParams['user']['user_id']
    Or are you after the full user record?

    You can get the user's details using the getUserByUserId function in the user model.

    I believe the getIdentities function was previously used to get a user's contact details. This has moved to custom fields that's why the getIdentities function no longer works.
     
    Wuebit likes this.
  5. Wuebit

    Wuebit Well-Known Member

    Ah yes sorry Chris I am trying to get the users custom field (I need to get some kip I think or more coffee)

    This is what I used to use.
    Code:
    $userModel = XenForo_Model::create('XenForo_Model_User');
                    $identities = $userModel->getIdentities($hookParams['user']['user_id']);
    
                    if (!empty($identities['twitter'])) {
                        $twitterId = $identities['twitter'];
                        $ourTemplate = $template->create('xen_profile_twitter_main');
                        $ourTemplate->setParam('twitter', $twitterId);
                        $contents .= $ourTemplate->render();
                    }
     
    Last edited: Dec 10, 2013
  6. Wuebit

    Wuebit Well-Known Member

    Chris would it be this than?

    Code:
                    $userModel = XenForo_Model::create('XenForo_Model_User');
                    $identities = $userModel->getUserIdFromUser($hookParams['user']['user_id']);
    
    It gives no errors but also nothing shows.
     
  7. xf_phantom

    xf_phantom Well-Known Member

    What are you trying to achieve?
    The identities system was replaced with the custom fields
     
  8. Daniel Hood

    Daniel Hood Well-Known Member

    Think you're looking for

    PHP:
    $userModel XenForo_Model::create('XenForo_Model_User');
    $identities $userModel->getFullUserById($hookParams['user']['user_id']);
     
    Wuebit likes this.
  9. Wuebit

    Wuebit Well-Known Member

    I was trying to add a twitter feedbox in the profile (like my old addon) But due to my coding skills ive give up lol. Coding is not for me that's for sure.
     
  10. Wuebit

    Wuebit Well-Known Member

    I still can't seem to get it to work tho.

    PHP:
    <?php

    class Wuebit_Model_index
    {
        public static function 
    templateHook($hookName, &$contents, array $hookParamsXenForo_Template_Abstract $template)
        {
            switch (
    $hookName)
            {
                case 
    'member_view_sidebar_middle2':
                {
                    
    $userModel XenForo_Model::create('XenForo_Model_User');
                    
    $identities $userModel->getFullUserById($hookParams['user']['user_id']);

                    if (!empty(
    $identities['twitter'])) {
                        
    $twitterId $identities['twitter'];
                        
    $ourTemplate $template->create('Wuebit_Twitter_Profile_Main');
                        
    $ourTemplate->setParam('twitter'$twitterId);
                        
    $contents .= $ourTemplate->render();
                    }
                    break;
                }
            }
        }
    }
    It seem's not to add the template on that hook.
     
    Daniel Hood likes this.
  11. Chris D

    Chris D XenForo Developer Staff Member

    Sorry it too me so long to respond.

    I think you ought to start again from scratch.

    There's a heck of a lot of new stuff in XenForo 1.2.

    One such thing is Template Modifications which basically enable you to specify a template, find some code within it, and replace it with your own code. It's much easier and much more flexible. Template hooks are officially deprecated. And although technically they should still work, they aren't as favourable as the Template Modification system.

    Also, as the contact information is now stored in custom fields, you don't even need any custom PHP to fetch them.

    Once you've added your template code using a template modification, you can get the value of a user's Twitter account using:

    Code:
    {$user.customFields.twitter}
     
    Wuebit and xf_phantom like this.
  12. Wuebit

    Wuebit Well-Known Member

    Wow oh wow that was SOO much easier lol thanks everyone.
     

Share This Page