XF 2.1 Need a guide for php callback widget

nektarios

Member
Hi.

I'm trying to find a guide or some help for creating a php callback widget.
I tried the documentation but I cannot see anything specific there. Even when I try to create a new php widget the help I get from the screen presented is really minimal.

Can you please tell me where to start? I'm really lost.

Thank you.
 
How to create a widget? Is creating an HTML widget in admin panel the only way?
How to connect it to a template?
How to connect external data (i.e., or from a file, or externa Database)?

Thank you.
 
How to create a widget? Is creating an HTML widget in admin panel the only way?
How to connect it to a template?
How to connect external data (i.e., or from a file, or externa Database)?

Thank you.
If you want you can take a look at the resources area. You have some add-on with widget : you can look into the code to see how it work ;)
 
Thank you. Basically, there is no resource.
Here is some widget :

;)
 
Thank you for your help.

I managed to create a php callback widget with simple html but I need now to connect to another database and get some data.

I use mysqli to connect but I get and error. Can you please help?

Code:
class Tips{
  
    public static function getHtml() {
        
        $DbHost    = '127.0.0.1';   
        $DbUser     = '*****';       
        $DbPassword = '*****';   
        $DbName = '****';     
        
        $connection = new mysqli($DbHost, $DbUser, $DbPassword, $DbName);  /* This is line 35*/
        if($connection->connect_error){
            trigger_error('Database connection failed: ' . $connection->connect_error, E_USER_ERROR);
        }
    }
}

I get this error:

An exception occurred: [Error] Class 'TIPS\mysqli' not found in src/addons/TIPS/Tips.php on line 35
 
Thank you for your help.

I managed to create a php callback widget with simple html but I need now to connect to another database and get some data.

I use mysqli to connect but I get and error. Can you please help?

Code:
class Tips{
 
    public static function getHtml() {
       
        $DbHost    = '127.0.0.1';  
        $DbUser     = '*****';      
        $DbPassword = '*****';  
        $DbName = '****';    
       
        $connection = new mysqli($DbHost, $DbUser, $DbPassword, $DbName);  /* This is line 35*/
        if($connection->connect_error){
            trigger_error('Database connection failed: ' . $connection->connect_error, E_USER_ERROR);
        }
    }
}

I get this error:

An exception occurred: [Error] Class 'TIPS\mysqli' not found in src/addons/TIPS/Tips.php on line 35

Go there to know how to connect to another Database, it's easy: https://xenforo.com/community/threads/how-to-connect-to-other-database-in-xf2.139720/
 
Top Bottom