XF 2.0 PHP callback from template

AlessioDP

Member
I have a problem to make a PHP call via a template modification.

For example, I want to call testMethod inside my Listener class passing a string parameter. After some calculations I want that method returns to the template the result like an html/string.

Is it possible?
 
If your callback returns a string, it will.

return $yourstring;

It doesn't works :(

Code:
The callback method methodName does not appear to indicate a read only function so cannot be called.

That's the code:
Code:
public static function methodName($str)
    {
        return $str."TEST";
    }
 
Your function is not correct.

I assume you're putting $str as the first parameter in the params in the template call...

Code:
public static function methodName($contents, $params)
{
    return $params[0]."TEST";
}

If that doesn't work, then I have no idea why it won't. It works for me.
 
Nothing! :(
I tested a lot of ways:
Code:
<p>
    <xf:callback class="Into\\Addon\\Listener" method="methodName" params="['abc']">
    </xf:callback>
</p>
$0
and:
Code:
<xf:callback class="Into\Addon\Listener" method="methodName" params="['abc']">
</xf:callback>
<xf:callback class="Into\Addon\Listener" method="methodName">
</xf:callback>
 
The first way would be the correct way.

The problem is most likely in your class php.
 
The error is right there.

The “methodName” method name is not allowed. Update it in your PHP class and template to be “getString” rather than “methodName” and it should work.

As a general rule, the method name should indicate that it is a read only function like getX, hasX, canX, readX etc.
 
LOL! I just assumed he was editing the real name and using methodName.

Guess I should remember the old saying about assume. :D
 
The error is right there.

The “methodName” method name is not allowed. Update it in your PHP class and template to be “getString” rather than “methodName” and it should work.

As a general rule, the method name should indicate that it is a read only function like getX, hasX, canX, readX etc.

Now it works :)

Thank you about the info, is there a doc about every xf:tag or something like that? Because i'm just using
https://xf2demo.xenforo.com/dev-docs/

LOL! I just assumed he was editing the real name and using methodName.

Guess I should remember the old saying about assume. :D
Nope, I didn't know that :S
 
Top Bottom