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

CallBack to get boardstatistics

Discussion in 'XenForo Development Discussions' started by Memo, Nov 30, 2013.

  1. Memo

    Memo New Member

    Hi,
    I'm trying to create a callback to get the boardtotals and active users and pass it to a view but am getting
    .
    Here my code:
    PHP:
    <?php
    static function respond(XenForo_ControllerPublic_Abstract $controllerXenForo_ControllerResponse_AbstractXenForo_ControllerPublic_Forum &$response)
        {
            
    $response->templateName "_page_node.29";
            
    $response->params['boardTotals'] = self::_getBoardTotals();
           
        }
    ?>        
    What am I not doing correctly?
    Thanks,
     
  2. Liam W

    Liam W Well-Known Member

    You don't have a class defined for the function.

    EDIT: Also, use the code block, and select PHP.
     
  3. Memo

    Memo New Member

    Can u be a bit more specific
     
  4. Liam W

    Liam W Well-Known Member

    All functions have to be defined in a class to be called statically, and those that aren't static have to be part of a class:

    PHP:
    <?php

    class FolderInLibrary_PhpFileName {
       
        public static function 
    respond(XenForo_ControllerPublic_Abstract $controllerXenForo_ControllerResponse_Abstract &$response)
        {
            <
    the code>
        }
       
    }

    ?>
    Also, it looks like the callback signature is wrong.
     
  5. Jeremy

    Jeremy XenForo Moderator Staff Member

    PHP:
    static function respond(XenForo_ControllerPublic_Abstract $controllerXenForo_ControllerResponse_AbstractXenForo_ControllerPublic_Forum &$response)
    That is the function creation signature for a static function within a PHP class. You are missing the class.
     
  6. Memo

    Memo New Member

    I'm trying to call the _getBoardTotals method from the XenForo_ControllerPublic_Forum class
     
  7. Memo

    Memo New Member

    Thank you. I have changed the code:
    PHP:
    <?php
    class karamel_home_home1 {
    public static function 
    respond(XenForo_ControllerPublic_Abstract $controllerXenForo_ControllerResponse_AbstractXenForo_ControllerPublic_Forum &$response)
        {
            
    $response->templateName "_page_node.29";
            
    $response->params['boardTotals'] = self::_getBoardTotals();
           
        }
    }
    ?>    
    Now I'm getting error:
     
  8. Liam W

    Liam W Well-Known Member

    That's because the callback signature is incorrect - you don't define a variable for the second parameter.
     
  9. xf_phantom

    xf_phantom Well-Known Member

    Is this a page callback class?

    If yes => You don't have a method _getBoardTotals in your callback class. You can't just call _getBoardTotals and hope that you'll get the value:p
     
    Liam W likes this.
  10. Liam W

    Liam W Well-Known Member

    Good point ;)

    Also, the file should be located at library/karamel/home/home1.php :)
     
  11. Memo

    Memo New Member

    Thank you, thank you so much.
    Can u pls just write the code as it should be, I really have a hard time understanding it.
     
  12. Memo

    Memo New Member

    PHP:
    <?php
    class karamel_home_home1 {
    public static function 
    respond()
        {
            
    $stats = new XenForo_ControllerPublic_Forum();
            
    $response->templateName "_page_node.29";
            
    $response->params['boardTotals'] = $stats->_getBoardTotals();
           
        }
    }

    $params= new karamel_home_home1();
    $params->respond();
    ?>        
    Is this correct this way?
     

Share This Page