XF 2.0 <xf:callbac> shows error when I want call PHP file

Parjam

Member
I just created this file in library/MyCard/index.php and added this code in it

Code:
class CardCoontroller{
    public static function getCard() {
        return 'test data';
    }
}

and in edit template -> member_view added this code
Code:
<xf:callback class="CardCoontroller" method="getCard"></xf:callback

But I get this error:
Code:
Callback CardCoontroller::getCard is invalid (error_invalid_class).

How can I fix it?
 
I just move my file to public_html/src/addons/ ? the PHP File? or public_html/src/addons/XF or shoud I create folder?
 
I just move my file to public_html/src/addons/ ? the PHP File? or public_html/src/addons/XF or shoud I create folder?
You need to follow the instructions in that link in order to create an addon before you can even begin to think about files.

Please make sure you read the documentation before asking any questions, as otherwise you're just going to get a bunch of "read the manual" replies :)


Fillip
 
I have a problem with understanding the concept. please help me a little.
I made a folder in addons -> OWN -> Cards
and 2 files addon.json and Setup.php

Now I just need a function that returns a simple data. Where can I put it? Should I create another PHP file in there? I just confused by docs. Just need to add a PHP file included a function that returns some text and import in by callback trick in the view file.

Thanks a lot.
 
Read the other links.

Vendor = OWN
Addon = Cards
Class = your php class inside a file which you have to create
 
I tried this
Code:
<xf:callback class="OWN\Cards\CardCoontroller" method="getCard"></xf:callback>

But getting this error:
Code:
Callback OWN\Cards\CardCoontroller::getCard is invalid (error_invalid_class).

In this address /home/mysite/public_html/src/addons/OWN/Cards/index.php

Where is the wrong part?
 
Did you create the add-on using the php cmd.php xf-addon:create command as described in the manual link I gave?

Did you assign a name space in your PHP file?

Is your PHP file named correctly?

There are too many questions that need to be answered for anyone to answer your question. It is truly a matter of reading and understanding what's in the manual.
 
Did you create the add-on using the php cmd.php xf-addon:create command as described in the manual link I gave?

Did you assign a name space in your PHP file?

Is your PHP file named correctly?

There are too many questions that need to be answered for anyone to answer your question. It is truly a matter of reading and understanding what's in the manual.


Yes, I did. This is my new index.php addon content:
Code:
<?php
namespace rCard;
class getCard
{
    public static function fetchCardInfo(\XF\SubContainer\Import $container, \XF\Container $parentContainer, array &$importers)
    {
        return 'ddddd';
    }
}
In address /home/iptvcommunity/public_html/src/addons/rCard/index.php
and I set "legacy_addon_id": "rescard" in addon.json

Dear my question is clear. now I have an index file and a class and function and namespace. whole if these should return that text 'ddddd'; My question is that is that enough for this simple add-on? How can I fetch function fetchCardInfo in my view file?I tried this code:

Code:
<xf:callback class="rCard\getCard" method="fetchCardInfo"></xf:callback>
 
Last edited:
You need to at least rename your index.php file in the Cards folder to "CardCoontroller.php" to use that callback. It's also unlikely that your namespace is really "rCard",

You really need to read the documentation again carefully.
 
just please tell me I can rename all of them. Just tell me please what should I name the folder, class, file.php, namespace and how I fetch it in callback tag.
I will do it
 
Top Bottom