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

CallBack to get boardstatistics

Memo

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

Liam W

Well-known member
#4
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 $controller, XenForo_ControllerResponse_Abstract &$response)
    {
        <the code>
    }
   
}

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

Jeremy

Well-known member
#5
PHP:
static function respond(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract, XenForo_ControllerPublic_Forum &$response)
That is the function creation signature for a static function within a PHP class. You are missing the class.
 

Memo

New member
#7
Thank you. I have changed the code:
PHP:
<?php
class karamel_home_home1 {
public static function respond(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract, XenForo_ControllerPublic_Forum &$response)
    {
        $response->templateName = "_page_node.29";
        $response->params['boardTotals'] = self::_getBoardTotals();
       
    }
}
?>
Now I'm getting error:
Fatal Error: syntax error, unexpected ',', expecting '&' or T_VARIABLE -library/karamel/home/home1.php:3
 

Liam W

Well-known member
#8
Thank you. I have changed the code:
PHP:
<?php
class karamel_home_home1 {
public static function respond(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract, XenForo_ControllerPublic_Forum &$response)
    {
        $response->templateName = "_page_node.29";
        $response->params['boardTotals'] = self::_getBoardTotals();
      
    }
}
?>
Now I'm getting error:
That's because the callback signature is incorrect - you don't define a variable for the second parameter.
 

xf_phantom

Well-known member
#9
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
 
#12
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?