idebuglife Posted January 7, 2020 Share Posted January 7, 2020 (edited) 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. Why is the following not working? I started with the widget example code but modified it slightly to get this... 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 January 7, 2020 by idebuglife 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 7, 2020 Share Posted January 7, 2020 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); 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. 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. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.