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

Online Members on External Page returning 0

Discussion in 'XenForo Development Discussions' started by LPH, Apr 14, 2014.

  1. LPH

    LPH Well-Known Member

    Here is the code:

    $dependencies = new XenForo_Dependencies_Public();




    $params $dependencies->getEffectiveContainerParams(array(), new Zend_Controller_Request_Http());

    $template =$dependencies->createTemplateObject('sidebar_online_users'$params);

    The code returns

    Members Online Now
    Total: 0 (members: 0, guests: 0, robots: 0)
    What am I doing wrong to not get the number of members, etc returned?
  2. Chris D

    Chris D XenForo Developer Staff Member

    You are fetching the container params. These are the params that are used outside of the content, eg headers, nav tabs etc.

    The params aren't going to just be available somewhere. Instead you are going to need to inspect the existing code, see how those params are got and then pass them to the template.

    Everything else is correct. It's just a case of putting the right stuff in $params
  3. LPH

    LPH Well-Known Member

    As always, Thank you.

    PS. I searched here yesterday several times and found nothing. I looked this morning and found multiple threads on this same topic. Oops.
    Last edited: Apr 14, 2014
  4. LPH

    LPH Well-Known Member

    @Chris D et al.

    Sorry - but I have more dumb questions. Chris set me in the right direction by looking at params and I also realized that the session was not in the code. This has now been added and the code almost works. Sadly, the links are all wrong. They are not actually going to the /community/members but to /members ...

    Is there a good way to fix the links so that they would go to the proper places? Does this mean extending a model in XenForo?

    Here is my current code (if this helps others):

    $dependencies = new XenForo_Dependencies_Public();
    /** * Start session  ( the $XF is from XenWord ) */
    $sessionModel $XF->getModelFromCache('XenForo_Model_Session');
    $visitor XenForo_Visitor::getInstance();
    /** * Pull onlineUsers */
    $onlineUsers $sessionModel->getSessionActivityQuickList($visitor->toArray(), array('cutOff' => array('>',$sessionModel->getOnlineStatusTimeout())), ($visitor['user_id'] ? $visitor->toArray() : null));
    $params = array('onlineUsers' => $onlineUsers,'visitor' => $visitor);
    $template =$dependencies->createTemplateObject('sidebar_online_users'$params);
    Screen Shot 2014-04-15 at 12.41.18 PM.png

Share This Page