Jump to content

Custom widget frustrations (debugging is impossible)


idebuglife

Recommended Posts

  1. How are we supposed to debug our code while building widgets in WHMCS? I have struggled to get any kind of output with var_dump, print_r, or dd() functions. 
  2. Why is the following not working? I started with the widget example code but modified it slightly to get this...
  3. The widget documentation is very weak, so I must unfortunately open a discussion here. I hope the answer to this will serve other people in the future with the same problem, surely I'm not the only one.
<?php

add_hook('AdminHomeWidgets', 1, function() {
    return new AwsMaintEventsWidget();
});


class AwsMaintEventsWidget extends \WHMCS\Module\AbstractWidget
{
    protected $title = 'Upcoming AWS Maintenance';
    protected $description = 'AWS maintenance events on the horizon...';
    protected $columns = 1;
    protected $weight = 1000;
    protected $cache = true;

    public function getData()
    {

        $test = 'josiahhh';
        $testtwo = 'dunno';

        return array(
           'counts' => $testtwo,
           'events' => $test,
        );
    }

    public function generateOutput($data) {

        $event = $data['events'];

        return <<<EOF
<div>
    <span>{$event}</span>
</div>
EOF;
    }

}

 

But oddly enough if I instead use this code from the "example widget" the documentation provides (see below) for the public function "getData()", it somehow *works*...my code is basically the same but simpler and doesn't!!?

 

    public function getData()
    {
        $counts = localApi('GetTicketCounts', array());

        $tickets = localApi('GetTickets', array('status' => 'Awaiting Reply', 'limitstart' => '0', 'limitnum' => '5'));

        return array(
            'tickets' => array(
                'counts' => $counts,
                'recent' => (isset($tickets['tickets']['ticket'])) ? $tickets['tickets']['ticket'] : [],
            ),
        );
    }

 

Edited by idebuglife
Link to comment
Share on other sites

11 hours ago, idebuglife said:

How are we supposed to debug our code while building widgets in WHMCS? I have struggled to get any kind of output with var_dump, print_r, or dd() functions. 

you should just need to return the print_r instead of the EOF code...

return print_r($event);

RSKEek5.png

11 hours ago, idebuglife said:

Why is the following not working? I started with the widget example code but modified it slightly to get this...

I copied & pasted that exact code into a new blank widget file and it worked fine.

g6ibaDQ.png

11 hours ago, idebuglife said:

The widget documentation is very weak

I wouldn't disagree with that... you'll learn more by examining the code of the other existing widgets - nearly all of them are not encrypted.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated