Xataface 2.0
Xataface Application Framework
Public Member Functions
dataface_actions_export_json Class Reference

Action to export a record or a set of records in JSON format. More...

Public Member Functions

 handle (&$params)

Detailed Description

Action to export a record or a set of records in JSON format.

This action takes the standard Xataface URL conventions to select records.

See also:
Xataface URL Conventions

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.

ParameterDescriptionRequiredDefault Value
-mode Whether to retrieve the current set specified (i.e. based on -skip and -limit params)
  • or to return the current record (i.e. based on the -cursor param). Possible values include:
    • list - To indicate a list.
    • browse - To just get the current record.
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.

Permissions

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'.

Examples

Given a table "my_groups" with 3 records:

With no parameters:

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

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

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

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

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"}]
Attention:
For this to work you also need to specify the -mode=browse attribute so that Xataface knows that you intend to return the current record rather than the full found set. Otherwise it will return the set as if it has no search parameters.

Definition at line 134 of file export_json.php.


Member Function Documentation

handle ( &$  params)

Definition at line 135 of file export_json.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations