Site icon Web Niraj

Parse.com: Using DataTypes, Pointers and ACL in PHP and JavaScript

Despite it’s short-comings, Parse.com is a very good cloud database solution for light-weight applications and even prototyping. Parse.com makes it easily for you to reference data from other table using Pointers (similar to joining in SQL) and lets you secure data using ACL on a row-by-row basis. One of the most common question I get with Parse is how to use Pointers and ACL – this tutorial answers both.

Pointers and DataTypes in PHP

If you’re using the Parse.com PHP SDK, using pointers is easy thanks to the dataType function. The dataType provides support for the various data-types supported by Parse, including date, pointers, bytes and geopoint. Creating a pointer to another table can be achieved like this:

See the gist on github.

The above example also include how to set ACL permissions. In the above code, we only allow read access to the User it belongs to. Public read access is disabled, and no one is allowed to write data.

Pointers and DataTypes in JavaScript

The below code achieves the same result as the PHP code above. The way pointers and dataTypes work in JavaScript are slightly different. The ACL code in JavaScript is very similar to the PHP version.

See the gist on github.

PHP DataType Examples

Here is an example of the various dataTypes the PHP SDK supports (note that there are a few more dataTypes that are supported):

See the gist on github.

JavaScript DataType Examples

Once again, I’ve included how to do the PHP examples above using JavaScript.

See the gist on github.

PHP ACL Examples

You can give read / write access to public (logged or anonymous) users, as well as specific users. There are several functions available to set read / write access, as shown in the code below:

See the gist on github.

JavaScript ACL Examples

The code below shows how to set ACL in JavaScript. It’s a copy of the permissions set in the PHP example above.

See the gist on github.


Have any questions, or stuck with data types or ACL? Tell us in the comments section below.

Exit mobile version