DataMapper OverZealous Edition


Included Extensions

DMZ includes the following extensions. $object refers to the DataMapper model that it is being used on.

json: JSON-Encoding and Decoding Methods

Converts an object to and from a JSON-encoded string.

to_json($fields, $pretty_print)

Converts the $object into a JSON-encoded string. Usage:

$u = new User();
$u->set_json_content_type();
echo $u->to_json(array('id', 'name', 'email'), TRUE);

from_json($json, $fields)

Stores values encapsulated in a JSON-encoded string back on the $object. Usage:

$json = $this->input->post('notedata');
$n = new Note();
if($n->from_json($json))
{
    // TODO: verify input, save changes
}
else
{
    show_error('Invalid input');
}

set_json_content_type()

A simple method used to set the proper content type header (application/json) for JSON files.