CallBack to get boardstatistics

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
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,
 
You don't have a class defined for the function.

EDIT: Also, use the code block, and select PHP.
 
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.
 
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.
 
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
 
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.
 
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
 
Is this a page callback class?

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

Good point ;)

Also, the file should be located at library/karamel/home/home1.php :)
 
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.
 
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?
 
Top Bottom