![]() |
Xataface 2.0
Xataface Application Framework
|
Action to export a record or a set of records in JSON format. More...
Public Member Functions | |
handle (&$params) |
Action to export a record or a set of records in JSON format.
This action takes the standard Xataface URL conventions to select records.
This action will always return a JSON array. If no record is found then it will be an empty array. If only one record is selected, then it will be an array with one item. Etc...
In addition to the standard Xataface URL conventions the following parameters may be used.
Parameter | Description | Required | Default Value |
---|---|---|---|
-mode | Whether to retrieve the current set specified (i.e. based on -skip and -limit params)
| No | list |
--displayMethod | The method to use to render the field content. Xataface includes different methods to get field values. The most basic is Dataface_Record::val() which just returns the value as it is stored (e.g. dates are stored as an associative array, integers are ints, etc... The next step up is Dataface_Record::display() which renders the value as a string, and obeys permissions. The highest level is htmlValue() that prepares output for HTML display. | No | val |
--fields | A list of fields to be included separated by spaces. | No | All native and grafted fields in the table. Does not include calculated fields. |
Both the 'view' and the 'export_json' permissions must be granted in order for the field value to be included in output. If the 'export_json' permission is not granted, the field will be completely omitted. If the export_json permission is granted but the view permission is not granted, then the field will be displayed as 'NO ACCESS'.
Given a table "my_groups" with 3 records:
URL: index.php?-table=my_groups&-action=export_json Output:
[ {"group_id":"1","group_name":"shannah","access_level":"3"}, {"group_id":"3","group_name":"FCAT Group Test","access_level":"3"}, {"group_id":"4","group_name":"Faculty of Education","access_level":"3"} ]
Using the --fields parameter to to only retrieve the group_id and group_name.
URL: index.php?-table=my_groups&-action=export_json&--fields=group_id%20group_name Output:
[ {"group_id":"1","group_name":"shannah"}, {"group_id":"3","group_name":"FCAT Group Test"}, {"group_id":"4","group_name":"Faculty of Education"} ]
Using the --displayMethod parameter to tell Xataface to render values with the Dataface_Record::display() method. This will result in the access_level field displaying the human readable value (because it uses a vocabulary) instead of the access level integer.
URL: index.php?-table=my_groups&-action=export_json&--displayMethod=display Output:
[ {"group_id":"1","group_name":"shannah","access_level":"Manager"}, {"group_id":"3","group_name":"FCAT Group Test","access_level":"Manager"}, {"group_id":"4","group_name":"Faculty of Education","access_level":"Manager"} ]
Using the -mode Parameter to cause only a single record to be returned based on the -cursor parameter.
URL: index.php?-table=my_groups&-action=export_json&-mode=browse&-cursor=1 Output:
[{"group_id":"3","group_name":"FCAT Group Test","access_level":"3"}]
Using the -recordid parameter (supported by Xataface) to select a single record by the Xataface Record ID.
URL: index.php?-table=my_groups&-action=export_json&-mode=browse&-recordid=my_groups%3Fgroup_id%3D3 Output:
[{"group_id":"3","group_name":"FCAT Group Test","access_level":"3"}]
Definition at line 134 of file export_json.php.
handle | ( | &$ | params | ) |
Definition at line 135 of file export_json.php.