JSONResult

The class JSONResult encapsulates the communication with the web interface.

Each object contains a Result, which informs the web interface whether this request was successful (Result=true) or not (Result=false). The Result of new initialized JSONResult objects is false. Use the method setResult($success) to set the result to true.

There are two strings, which are displayed to the user. Message and Error. Message will be displayed, when the result is true. Error when the result is false. The setter methods are setMessage($message) and setError($error).

To set widget data use the method setData($key, $value). $key is the ID of the widget and $value the value to set.

Runtime options can be set by using setOption($key, $optname, $optvalue). $key is the ID of the widget, $optname the name of the option and $optvalue the value of the option.

Methods

Name Parameter Return value Description
setResult Bool success $this Operation successful or not
getResult Bool Returns the current result value
setMessage String msg $this Prints a message in green
setError String msg $this Prints a message in red
setData String key, Object val $this Sets the content of a widget
setOption String key, String optname, Object $optval $this Sets a runtime option of a widget
printJSON Sends the JSONObject to the web interface
__toString Serializes the object

Examples

$result = new JSONResult();
$result->setResult(true);
$result->setData('textbox', 'Text String');
$result->setData('checkbox', true);
$result->setOption('textbox', 'visible', false);
echo $result;

Links

You could leave a comment if you were logged in.