-
Notifications
You must be signed in to change notification settings - Fork 323
How To: Drive Smashing widgets with PHP
Toby Creek edited this page Oct 1, 2020
·
7 revisions
To leverage an existing code base or separate the dashboard from the data source using only an HTTP connection, it may be desirable to POST data to the widgets easily using PHP's curl() functions.
- Create a function library to allow POSTing data to the dashing widget.
This repository has a function library
This is an example Smashing job
-
Edit the function library to insert the Smashing widget URL and the auth token.
-
Use PHP's
json_encode
function to turn an array or object into a JSON string. -
Use the function library's
send_event()
function to POST data.
- Sending data to a list widget, including moreinfo.
$json=@array();
$json['items'][0]['label']="Monday";
$json['items'][0]['value']="8:00am - 6:00pm";
$json['items'][1]['label']="Tuesday";
$json['items'][1]['value']="8:30am - 4:30pm";
$json['moreinfo']="And then, beer!";
send_event('labhours', json_encode($json));
- Sending the result of a database query to a list widget
$result=mysqli_query($db, "SELECT fruit AS label, SUM(fruit) AS value FROM fruitbystate GROUP BY fruit");
$json=@array();
$json['items']=mysqli_fetch_all($result, MYSQLI_ASSOC);
send_event('fruitbystate', json_encode($json));
- Home
- Dashing Workshop
- Installation
- Widgets
- Configuration
- Security
- Troubleshooting
- Deploying dashboards
- How Tos
- How to: post data to your dashboard and widgets
- How to: Define a data model and store history data to database
- How to: Prevent a job from overlapping with itself
- How to: Send HTML data to your widgets
- How to: Send mysql data to your widgets
- How to: Setup a Graph
- How to: Store data to and display from database
- How to: Update a Dashboard using a spreadsheet
- How to: update dashboard in Django
- How to: Update font awesome fonts from version 3 to 4
- How to: Use New Relic with Dashing
- How to: precompile assets
- Development