-
Book Overview & Buying
-
Table Of Contents
concrete5 Cookbook
By :
Most PHP installations include handy JSON functions such as encode_json and decode_json, which allows developers to easily generate JSON data to pass through to the user's browser. concrete5 includes the JSON helpers to allow you to encode and decode JSON even on systems that do not have those functions available. This is particularly useful if you are developing an add-on that will run on several different types of environments.
Load the JSON helper:
$json = Loader::helper('json');Create an array that will be converted to a JSON string:
$data = array( 'name' => 'John Doe', 'age' => '31' );
Encode the array into a JSON string:
$jsonStr = $json->encode($data);
Decode the JSON string back to an object:
$newObject = $json->decode($jsonStr);
If the native JSON functions are present, these helper functions will simply wrap around those. On environments where the JSON encode and decode functions are unavailable...
Change the font size
Change margin width
Change background colour