Json_decode

If you haven’t mix up your project yet, please head over khổng lồ the PHPhường SDK cài đặt guide or read the Installation section below to lớn get up và running. You can also kiểm tra out our API Reference for more detailed information about our SDK.

Bạn đang xem: Json_decode

The Parse platsize provides a complete backkết thúc solution for your Smartphone application. Generally, our goal is lớn eliminate the need for managing servers & writing server-side code. Our PHP.. SDK is for those applications & situations where server-side code is necessary, or simply preferred.

The Parse PHP SDK is fully open source, and anyone can contribute lớn make it better, or make their own changes if necessary. Chechồng out the GitHub repository for more information.

The Parse PHP. SDK requires version 5.4 or greater of the PHP runtime.


Want to contribute to lớn this doc? Edit this section.
Installation

There are various ways to install & use this sdk. We’ll elaborate on a couple here.Note that the Parse PHP SDK requires PHP.. 5.4 or newer. It can also run on HHVM (recommended 3.0 or newer).

Install with Composer

, the PHP package manager. Then create a composer.json file in your projects root thư mục, containing:


"https://obatambeienwasirherbal.com/require"https://obatambeienwasirherbal.com.parseplatkhung.org/: "https://obatambeienwasirherbal.com.parseplatkhung.org/parse/php-sdk"https://obatambeienwasirherbal.com/ : "https://obatambeienwasirherbal.com.parseplatkhung.org/1.4.*"https://obatambeienwasirherbal.com.parseplatsize.org/
Run “composer install” lớn tải về the SDK & phối up the autoloader,và then require it from your PHP. script:


require "https://obatambeienwasirherbal.com.parseplatsize.org/vendor/autoload.php"https://obatambeienwasirherbal.com.parseplatkhung.org/;

Install with Git

You can clone down this sdk using your favorite github client, or via the terminal.


git clone https://github.com/parse-community/parse-php-sdk.git
You can then include the autoload.php tệp tin in your code khổng lồ automatically load the Parse SDK classes.


require "https://obatambeienwasirherbal.com.parseplatkhung.org/autoload.php"https://obatambeienwasirherbal.com/;

Install with another method

If you downloaded this sdk using any other means you can treat it lượt thích you used the git method above sầu.Once it’s installed you need only require the autoload.php lớn have sầu access to lớn the sdk.


Want to lớn contribute to this doc? Edit this section.
Setup

Once you have sầu access khổng lồ the sdk you’ll need to lớn set it up in order khổng lồ begin working with parse-VPS.

Initializing

After including the required files from the SDK, you need to lớn initialize the ParseClient using your Parse API keys:


ParseClient::initialize( $app_id, $rest_key, $master_key );
If your server does not use or require a REST key you may initialize the ParseClient as follows, safely omitting the REST key:


ParseClient::initialize( $app_id, null, $master_key );

Server URL

Directly after initializing the sdk you should phối the VPS url.


// Users of Parse Server will need to lớn point ParseClient at their remote URL and Mount Point:ParseClient::setServerURL("https://obatambeienwasirherbal.com/https://my-parse-VPS.com:port"https://obatambeienwasirherbal.com/,"https://obatambeienwasirherbal.com.parseplatkhung.org/parse"https://obatambeienwasirherbal.com.parseplatkhung.org/);
Notice Parse server’s default port is 1337 & the second parameter parse is the route prefix of your parse hệ thống.

For example if your parse server’s url is http://example.com:1337/parse then you can set the hệ thống url using the following snippet


ParseClient::setServerURL("https://obatambeienwasirherbal.com.parseplatsize.org/https://example.com:1337"https://obatambeienwasirherbal.com.parseplatkhung.org/,"https://obatambeienwasirherbal.com.parseplatkhung.org/parse"https://obatambeienwasirherbal.com/);

Server Health Check

To verify that the hệ thống url and mount path you’ve provided are correct you can run a health kiểm tra on your VPS.


$health = ParseClient::getServerHealth();if($health<"https://obatambeienwasirherbal.com/status"https://obatambeienwasirherbal.com/> === 200) // everything looks good!
If you wanted lớn analyze it further the health response may look something like this.


"https://obatambeienwasirherbal.com/status"https://obatambeienwasirherbal.com.parseplatsize.org/ : 200, "https://obatambeienwasirherbal.com/response"https://obatambeienwasirherbal.com.parseplatkhung.org/ : "https://obatambeienwasirherbal.com.parseplatkhung.org/status"https://obatambeienwasirherbal.com/ : "https://obatambeienwasirherbal.com/ok"https://obatambeienwasirherbal.com.parseplatkhung.org/
The ‘status’ being the http response code, và the ‘response’ containing what the server replies with.Any additional details in the reply can be found under ‘response’, and you can use them lớn check và determine the availability of parse-server before you make requests.

cảnh báo that it is not guaranteed that ‘response’ will be a parsable json array. If the response cannot be decoded it will be returned as a string instead.

A couple examples of bad health responses could include an incorrect mount path, port or tên miền.


// ParseClient::setServerURL("https://obatambeienwasirherbal.com.parseplatsize.org/http://localhost:1337"https://obatambeienwasirherbal.com.parseplatkhung.org/, "https://obatambeienwasirherbal.com/not-good"https://obatambeienwasirherbal.com/); "https://obatambeienwasirherbal.com.parseplatsize.org/status"https://obatambeienwasirherbal.com/: 404, "https://obatambeienwasirherbal.com.parseplatsize.org/response"https://obatambeienwasirherbal.com/: "https://obatambeienwasirherbal.com.parseplatkhung.org/...Cannot GET /not-good/health..."https://obatambeienwasirherbal.com.parseplatsize.org/// ParseClient::setServerURL("https://obatambeienwasirherbal.com.parseplatkhung.org/http://__uh__oh__.com"https://obatambeienwasirherbal.com/, "https://obatambeienwasirherbal.com.parseplatsize.org/parse"https://obatambeienwasirherbal.com.parseplatkhung.org/); "https://obatambeienwasirherbal.com.parseplatkhung.org/status"https://obatambeienwasirherbal.com.parseplatkhung.org/: 0, "https://obatambeienwasirherbal.com.parseplatsize.org/error"https://obatambeienwasirherbal.com/: 6, "https://obatambeienwasirherbal.com.parseplatsize.org/error_message"https://obatambeienwasirherbal.com.parseplatsize.org/: "https://obatambeienwasirherbal.com/Couldn"https://obatambeienwasirherbal.com/t resolve sầu host "https://obatambeienwasirherbal.com.parseplatkhung.org/__uh__oh__.com"https://obatambeienwasirherbal.com.parseplatsize.org/"https://obatambeienwasirherbal.com.parseplatkhung.org/
Keep in mind error và error_message may change depending on whether you are using the curl (may change across versions of curl) or stream client.

Http Clients

This SDK has the ability to lớn change the underlying http client at your convenience.The mặc định is khổng lồ use the curl http client if none is mix, there is also a stream http client that can be used as well.

Setting the http client can be done as follows:


// mix curl http client (default if none set)ParseClient::setHttpClient(new ParseCurlHttpClient());// set stream http client// ** requires "https://obatambeienwasirherbal.com/allow_url_fopen"https://obatambeienwasirherbal.com/ lớn be enabled in php.ini **ParseClient::setHttpClient(new ParseStreamHttpClient());
If you have a need for an additional http client you can request one by opening an issue or by submitting a lăng xê.

If you wish lớn build one yourself make sure your http client implements ParseHttpable for it be compatible with the SDK. Once you have a working http client that enhances the SDK feel free to submit it in a lăng xê so we can look into lớn adding it in.

Alternate CA File

It is possible that your local setup may not be able to lớn verify with peers over SSL/TLS. This may especially be the case if you vị not have sầu control over your local installation, such as for shared hosting.

If this is the case you may need lớn specify a Certificate Authority bundle. You can download such a bundle from http://curl.haxx.se/ca/cacert.pem to use for this purpose. This one happens to be a Mozilla CA certificate store, you don’t necessarily have sầu khổng lồ use this one but it’s recommended.

Once you have your bundle you can set it as follows:


// ** Use an Absolute path for your file! **// holds one or more certificates to verify the peer withParseClient::setCAFile(__DIR__ . "https://obatambeienwasirherbal.com.parseplatkhung.org//certs/cacert.pem"https://obatambeienwasirherbal.com.parseplatkhung.org/);
Want lớn contribute khổng lồ this doc? Edit this section.
Objects

ParseObject

Storing data on Parse is built around the ParseObject. Each ParseObject contains key-value pairs of JSON-compatible data. This data is schemaless, which means that you don’t need khổng lồ specify ahead of time what keys exist on each ParseObject. You simply set whatever key-value pairs you want, và our backkết thúc will store it.

For example, let’s say you’re tracking high scores for a game. A single ParseObject could contain:


score: 1337, playerName: "https://obatambeienwasirherbal.com/Sean Plott"https://obatambeienwasirherbal.com.parseplatkhung.org/, cheatMode: false
Keys must be alphanumeric strings. Values can be strings, numbers, booleans, or even sequential arrays & associative arrays - anything that can be JSON-encoded. chú ý however that Arrays and Associative sầu Arrays require separate methods to mix them on a ParseObject.

Saving Objects

Let’s say you want khổng lồ save the GameScore described above to the Parse Cloud. The interface is similar to a our other SDKs, including the save method:


$gameScore = new ParseObject("https://obatambeienwasirherbal.com.parseplatkhung.org/GameScore"https://obatambeienwasirherbal.com/);$gameScore->set("https://obatambeienwasirherbal.com/score"https://obatambeienwasirherbal.com.parseplatsize.org/, 1337);$gameScore->set("https://obatambeienwasirherbal.com/playerName"https://obatambeienwasirherbal.com/, "https://obatambeienwasirherbal.com.parseplatkhung.org/Sean Plott"https://obatambeienwasirherbal.com.parseplatkhung.org/);$gameScore->set("https://obatambeienwasirherbal.com.parseplatkhung.org/cheatMode"https://obatambeienwasirherbal.com.parseplatsize.org/, false);try $gameScore->save(); emang lại "https://obatambeienwasirherbal.com.parseplatkhung.org/New object created with objectId: "https://obatambeienwasirherbal.com.parseplatsize.org/ . $gameScore->getObjectId(); catch (ParseException $ex) // Exexinh đẹp any xúc tích that should take place if the save sầu fails. // error is a ParseException object with an error code và message. eđến "https://obatambeienwasirherbal.com.parseplatsize.org/Failed to lớn create new object, with error message: "https://obatambeienwasirherbal.com/ . $ex->getMessage();
After this code runs, you will probably be wondering if anything really happened. To make sure the data was saved, you can look at the Data Browser in your ứng dụng on Parse. You should see something like this:


There are two things to note here. You didn’t have to lớn configure or set up a new Class called GameScore before running this code. Your Parse tiện ích lazily creates this Class for you when it first encounters it.

There are also a few fields you don’t need lớn specify that are provided as a convenience. objectId is a quality identifier for each saved object. createdAt and updatedAt represent the time that each object was created and last modified in the cloud. Each of these fields is filled in by Parse, so they don’t exist on a ParseObject until a save operation has completed.

Retrieving Objects

Saving data khổng lồ the cloud is fun, but it’s even more fun lớn get that data out again. If the ParseObject has been uploaded to lớn the VPS, you can retrieve sầu it with its objectId using a ParseQuery:


$query = new ParseQuery("https://obatambeienwasirherbal.com/GameScore"https://obatambeienwasirherbal.com/);try $gameScore = $query->get("https://obatambeienwasirherbal.com.parseplatkhung.org/xWMyZ4YEGZ"https://obatambeienwasirherbal.com.parseplatkhung.org/); // The object was retrieved successfully. catch (ParseException $ex) // The object was not retrieved successfully. // error is a ParseException with an error code & message.
To get the values out of the ParseObject, use the get method.


$score = $gameScore->get("https://obatambeienwasirherbal.com.parseplatkhung.org/score"https://obatambeienwasirherbal.com.parseplatsize.org/);$playerName = $gameScore->get("https://obatambeienwasirherbal.com.parseplatkhung.org/playerName"https://obatambeienwasirherbal.com.parseplatsize.org/);$cheatMode = $gameScore->get("https://obatambeienwasirherbal.com.parseplatsize.org/cheatMode"https://obatambeienwasirherbal.com.parseplatsize.org/);
The four special values are provided as the result of methods:


$objectId = $gameScore->getObjectId();$updatedAt = $gameScore->getUpdatedAt();$createdAt = $gameScore->getCreatedAt();$acl = $gameScore->getACL();
If you need lớn refresh an object you already have sầu with the lademo data that is in the Parse Cloud, you can điện thoại tư vấn the fetch method lượt thích so:


$gameScore->fetch();
If you need lớn check if an object has been fetched, you can call the isDataAvailable() method:


if (!$gameScore->isDataAvailable()) $gameScore->fetch();

Updating Objects

Updating an object is simple. Just mix some new data on it & Gọi the save sầu method. For example:


// Create the object.$gameScore = new ParseObject("https://obatambeienwasirherbal.com/GameScore"https://obatambeienwasirherbal.com.parseplatkhung.org/);$gameScore->set("https://obatambeienwasirherbal.com.parseplatkhung.org/score"https://obatambeienwasirherbal.com.parseplatkhung.org/, 1337);$gameScore->set("https://obatambeienwasirherbal.com.parseplatkhung.org/playerName"https://obatambeienwasirherbal.com.parseplatsize.org/, "https://obatambeienwasirherbal.com.parseplatkhung.org/Sean Plott"https://obatambeienwasirherbal.com/);$gameScore->set("https://obatambeienwasirherbal.com/cheatMode"https://obatambeienwasirherbal.com/, false);$gameScore->setArray("https://obatambeienwasirherbal.com.parseplatkhung.org/skills"https://obatambeienwasirherbal.com.parseplatkhung.org/, <"https://obatambeienwasirherbal.com.parseplatsize.org/pwnage"https://obatambeienwasirherbal.com.parseplatsize.org/, "https://obatambeienwasirherbal.com.parseplatkhung.org/flying"https://obatambeienwasirherbal.com.parseplatsize.org/>);$gameScore->save();// Now let"https://obatambeienwasirherbal.com.parseplatsize.org/s update it with some new data. In this case, only cheatMode and score// will get sent lớn the cloud. playerName hasn"https://obatambeienwasirherbal.com.parseplatkhung.org/t changed.$gameScore->set("https://obatambeienwasirherbal.com.parseplatkhung.org/cheatMode"https://obatambeienwasirherbal.com/, true);$gameScore->set("https://obatambeienwasirherbal.com.parseplatkhung.org/score"https://obatambeienwasirherbal.com/, 1338);$gameScore->save();
Parse automatically figures out which data has changed so only “dirty” fields will be sent khổng lồ the Parse Cloud. You don’t need lớn worry about squashing data that you didn’t intover to lớn update.

Counters

The above sầu example contains a comtháng use case. The “score” field is a counter that we’ll need to continually update with the player’s latest score. Using the above method works but it’s cumbersome and can lead to lớn problems if you have sầu multiple clients trying lớn update the same counter.

To help with storing counter-type data, Parse provides methods that atomically increment (or decrement) any number field. So, the same update can be rewritten as:


$gameScore->increment("https://obatambeienwasirherbal.com.parseplatkhung.org/score"https://obatambeienwasirherbal.com/);$gameScore->save();
You can also increment by any amount by passing in a second argument khổng lồ increment. When no amount is specified, 1 is used by default.

Arrays

To help with storing array data, there are three operations that can be used to lớn atomically change an array associated with a given key:

add appover the given object khổng lồ the over of an array field. addUnique add the given object only if it isn’t already contained in an array field. The position of the insert is not guaranteed. remove remove all instances of the given object from an array field.

For example, we can add items khổng lồ the set-like “skills” field lượt thích so:


$gameScore->addUnique("https://obatambeienwasirherbal.com.parseplatsize.org/skills"https://obatambeienwasirherbal.com.parseplatkhung.org/, <"https://obatambeienwasirherbal.com/flying"https://obatambeienwasirherbal.com.parseplatkhung.org/>);$gameScore->addUnique("https://obatambeienwasirherbal.com.parseplatkhung.org/skills"https://obatambeienwasirherbal.com.parseplatsize.org/, <"https://obatambeienwasirherbal.com.parseplatsize.org/kungfu"https://obatambeienwasirherbal.com.parseplatsize.org/>);$gameScore->save();
lưu ý that it is not currently possible to lớn atomically add and remove items from an array in the same save. You will have to Điện thoại tư vấn save in between every different kind of array operation.

Encoding/Decoding

Using version 1.3.0 or later of the php sdk gives you the ability khổng lồ encode/decode instances of ParseObject.Encoding an object will give you a JSON encoded array that can be later decoded to get the original object baông chồng, unsaved changes included.


// create an object$obj = new ParseObject("https://obatambeienwasirherbal.com.parseplatsize.org/YourClass"https://obatambeienwasirherbal.com.parseplatsize.org/);$obj->set("https://obatambeienwasirherbal.com.parseplatsize.org/info"https://obatambeienwasirherbal.com.parseplatsize.org/, "https://obatambeienwasirherbal.com.parseplatkhung.org/an encodable object"https://obatambeienwasirherbal.com.parseplatkhung.org/);// encode this object$encoded = $obj->encode();// save sầu this encoded object somewhere for later use...// decode khổng lồ get our object as it was before,// unsaved changes included$decoded = ParseObject::decode($encoded);
An object that is encoded can easily be stored away, sent across the wire or even saved as a value under another ParseObject.This can be used to create a snapshot of an object at a point in time (unsaved changes included), allowing you lớn later go baông xã, decode and inspect that object later on.

Destroying Objects

To delete an object from the cloud:


$gameScore->destroy();
You can delete a single field from an object with the delete method:


// After this, the playerName field will be empty$gameScore->delete("https://obatambeienwasirherbal.com/playerName"https://obatambeienwasirherbal.com.parseplatsize.org/);// Saves the field deletion khổng lồ the Parse Cloud$gameScore->save();

Relational Data

Objects may have sầu relationships with other objects. For example, in a blogging application, a Post object may have many Comment objects. Parse supports all kind of relationships, including one-to-one, one-to-many, và many-to-many.

One-to-One & One-to-Many Relationships

One-to-one and one-to-many relationships are modeled by saving a ParseObject as a value in the other object. For example, each Comment in a blogging tiện ích might correspond to one Post.

To create a new Post with a single Comment, you could write:


// Create the post$myPost = new ParseObject("https://obatambeienwasirherbal.com.parseplatsize.org/Post"https://obatambeienwasirherbal.com.parseplatkhung.org/);$myPost->set("https://obatambeienwasirherbal.com/title"https://obatambeienwasirherbal.com.parseplatkhung.org/, "https://obatambeienwasirherbal.com.parseplatkhung.org/I"https://obatambeienwasirherbal.com/m Hungry"https://obatambeienwasirherbal.com/);$myPost->set("https://obatambeienwasirherbal.com/content"https://obatambeienwasirherbal.com/, "https://obatambeienwasirherbal.com/Where should we go for lunch?"https://obatambeienwasirherbal.com.parseplatsize.org/);// Create the comment$myComment = new ParseObject("https://obatambeienwasirherbal.com.parseplatkhung.org/Comment"https://obatambeienwasirherbal.com.parseplatkhung.org/);$myComment->set("https://obatambeienwasirherbal.com.parseplatsize.org/content"https://obatambeienwasirherbal.com.parseplatkhung.org/, "https://obatambeienwasirherbal.com/Let"https://obatambeienwasirherbal.com.parseplatsize.org/s do Sushirrilớn."https://obatambeienwasirherbal.com/);// Add the post as a value in the comment$myComment->set("https://obatambeienwasirherbal.com/parent"https://obatambeienwasirherbal.com/, $myPost);// This will save sầu both myPost và myComment$myComment->save();
Internally, the Parse framework will store the referred-to lớn object in just one place, khổng lồ maintain consistency. You can also link objects using just their objectIds like so:


$post = new ParseObject("https://obatambeienwasirherbal.com/Post"https://obatambeienwasirherbal.com.parseplatsize.org/, "https://obatambeienwasirherbal.com/1zEcyElZ80"https://obatambeienwasirherbal.com.parseplatsize.org/);$myComment->set("https://obatambeienwasirherbal.com/parent"https://obatambeienwasirherbal.com.parseplatsize.org/, $post);
By mặc định, when fetching an object, related ParseObjects are not fetched. These objects’ values cannot be retrieved until they have sầu been fetched like so:


$post = $fetchedComment->get("https://obatambeienwasirherbal.com/parent"https://obatambeienwasirherbal.com.parseplatsize.org/);$post->fetch();$title = $post->get("https://obatambeienwasirherbal.com.parseplatkhung.org/title"https://obatambeienwasirherbal.com/);

Many-to-Many Relationships

Many-to-many relationships are modeled using ParseRelation. This works similar khổng lồ storing an array of ParseObjects in a key, except that you don’t need to lớn fetch all of the objects in a relation at once. In addition, this allows ParseRelation khổng lồ scale to lớn many more objects than the array of ParseObject approach. For example, a User may have sầu many Posts that she might like. In this case, you can store the set of Posts that a User likes using relation. In order lớn add a Post khổng lồ the “likes” array of the User, you can do:


$user = ParseUser::getCurrentUser();$relation = $user->getRelation("https://obatambeienwasirherbal.com.parseplatkhung.org/likes"https://obatambeienwasirherbal.com.parseplatsize.org/);$relation->add($post);$user->save();
You can remove sầu a post from a ParseRelation:


$relation->remove($post);$user->save();
You can điện thoại tư vấn add and remove sầu multiple times before calling save:


$relation->remove($post1);$relation->remove($post2);$user->save();
You can also pass in an array of ParseObject khổng lồ add & remove:


$relation->add(<$post1, $post2, $post3>);$user->save();
By default, the array of objects in this relation are not downloaded. You can get an array of the posts that a user likes by using the ParseQuery returned by getQuery. The code looks like:


$postsLiked = $relation->getQuery()->find();// $postsLiked contains the posts that the current user likes.
If you want only a subset of the Posts, you can add extra constraints to lớn the ParseQuery returned by query lượt thích this:


$query = $relation->getQuery();$query->equalTo("https://obatambeienwasirherbal.com.parseplatsize.org/title"https://obatambeienwasirherbal.com/, "https://obatambeienwasirherbal.com.parseplatkhung.org/I"https://obatambeienwasirherbal.com/m Hungry"https://obatambeienwasirherbal.com/);$postsLiked = $query->find();// $postsLiked contains post liked by the current user which have sầu the title "https://obatambeienwasirherbal.com/I"https://obatambeienwasirherbal.com.parseplatsize.org/m Hungry"https://obatambeienwasirherbal.com.parseplatsize.org/.
For more details on ParseQuery, please look at the query portion of this guide. A ParseRelation behaves similar to lớn an array of ParseObject for querying purposes, so any query you can do on an array of objects, you can vị on a ParseRelation.

Data Types

So far we’ve used values with type String, Integer, và ParseObject. Parse also supports PHP.. DateTimes & null. You can nest PHP. arrays & associative arrays (JSON Objects) khổng lồ store more structured data within a single ParseObject. Overall, the following types are allowed for each field in your object:

String => String Number => Integer & float Bool => Boolean Array => PHP arrays Object => associative arrays (JSON Objects) Date => DateTime File => ParseFile Pointer => other ParseObject Relation => ParseRelation GeoPoint => ParseGeoPoint Null => null

Some examples:


$number = 42;$string = "https://obatambeienwasirherbal.com/the number is "https://obatambeienwasirherbal.com.parseplatkhung.org/ . $number;$date = new DateTime();$array = <$string, $number>;$object = <"https://obatambeienwasirherbal.com.parseplatsize.org/number"https://obatambeienwasirherbal.com.parseplatsize.org/ => $number, "https://obatambeienwasirherbal.com.parseplatkhung.org/string"https://obatambeienwasirherbal.com.parseplatsize.org/ => $string>;$geoPoint = new ParseGeoPoint(37.75, -122.68); // san fran$bigObject = new ParseObject("https://obatambeienwasirherbal.com.parseplatsize.org/BigObject"https://obatambeienwasirherbal.com.parseplatsize.org/);$bigObject->set("https://obatambeienwasirherbal.com.parseplatkhung.org/myNumber"https://obatambeienwasirherbal.com.parseplatsize.org/, $number);$bigObject->set("https://obatambeienwasirherbal.com.parseplatsize.org/myString"https://obatambeienwasirherbal.com.parseplatkhung.org/, $string);$bigObject->set("https://obatambeienwasirherbal.com/myDate"https://obatambeienwasirherbal.com.parseplatsize.org/, $date);$bigObject->setArray("https://obatambeienwasirherbal.com.parseplatkhung.org/myArray"https://obatambeienwasirherbal.com/, $array);$bigObject->setAssociativeArray("https://obatambeienwasirherbal.com.parseplatkhung.org/myObject"https://obatambeienwasirherbal.com/, $object);$bigObject->set("https://obatambeienwasirherbal.com/myGeoPoint"https://obatambeienwasirherbal.com.parseplatsize.org/, $geoPoint);$bigObject->set("https://obatambeienwasirherbal.com.parseplatkhung.org/anyKey"https://obatambeienwasirherbal.com/, null); // this value can only be saved to an existing key$bigObject->save();
We vị not recommend storing large pieces of binary data like images or documents on ParseObject. We recommend you use ParseFiles lớn store images, documents, và other types of files. You can do so by instantiating a ParseFile object and setting it on a field. See Files for more details.

For more information about how Parse handles data, kiểm tra out our documentation on Data.

Subclassing ParseObject

Each ParseObject is an instance of a specific subclass with a class name that you can use to distinguish different sorts of data. For example, we could gọi the high score object a GameScore. We recommend that you NameYourClassesLikeThis & nameYourKeysLikeThis, just to lớn keep your code looking pretty.

Xem thêm: Code Php Tìm Kiếm Giống Google, Tìm Kiếm Dữ Liệu Trong Php Và Mysql

To create a new subclass, create a new class which extends the ParseObject class, add the $parseClassName static property, & Gọi the registerSubclass method before use. Any ParseQuery will return instances of the new class for any ParseObject with the same class name.


class GameScore extends ParseObject public static $parseClassName = "https://obatambeienwasirherbal.com.parseplatkhung.org/GameScore"https://obatambeienwasirherbal.com.parseplatsize.org/;
// Do this once, at the start of your tiện ích, before ParseClient::initialize(...);GameScore::registerSubclass();// Create a new instance of that class.$gameScore = new GameScore();
You can add additional methods and properties khổng lồ your subclasses of ParseObject.


// A complex subclass of ParseObjectclass Monster extends ParseObject public static $parseClassName = "https://obatambeienwasirherbal.com/Monster"https://obatambeienwasirherbal.com.parseplatkhung.org/; public function hasSuperHumanStrength() return $this->get("https://obatambeienwasirherbal.com/strength"https://obatambeienwasirherbal.com/) > 18; public static function spawn($strength) $Boss = new Monster(); $monster->set("https://obatambeienwasirherbal.com/strength"https://obatambeienwasirherbal.com/, $strength); return $monster;
$Boss = Monster::spawn(200);echo monster->strength(); // Displays 200.emang lại monster->hasSuperHumanStrength(); // Displays true.
If you want lớn override the __construct method, make sure the first three params are exactly as same as the parent ParseObject constructor:


class GameScore extends ParseObject public static $parseClassName = "https://obatambeienwasirherbal.com.parseplatkhung.org/GameScore"https://obatambeienwasirherbal.com.parseplatkhung.org/; public function __construct($className = null, $objectId = null, $isPointer = false, $another_param) parent::__construct("https://obatambeienwasirherbal.com/GameScore"https://obatambeienwasirherbal.com/, $objectId, $isPointer); // ...
Want to lớn contribute khổng lồ this doc? Edit this section.
QueriesWe’ve already seen how a ParseQuery with get can retrieve a single ParseObject from Parse. There are many other ways to retrieve sầu data with ParseQuery - you can retrieve sầu many objects at once, put conditions on the objects you wish lớn retrieve, and more.

Basic Queries

In many cases, get isn’t powerful enough lớn specify which objects you want khổng lồ retrieve sầu. ParseQuery offers different ways to lớn retrieve an array of objects rather than just a single object.

The general pattern is lớn create a ParseQuery, put conditions on it, & then retrieve an Array of matching ParseObjects using find. For example, khổng lồ retrieve of the scores with a particular playerName, use the equalTo method to constrain the value for a key.


$query = new ParseQuery("https://obatambeienwasirherbal.com.parseplatsize.org/GameScore"https://obatambeienwasirherbal.com.parseplatsize.org/);$query->equalTo("https://obatambeienwasirherbal.com/playerName"https://obatambeienwasirherbal.com/, "https://obatambeienwasirherbal.com.parseplatkhung.org/Dan Stemkoski"https://obatambeienwasirherbal.com.parseplatkhung.org/);$results = $query->find();emang lại "https://obatambeienwasirherbal.com.parseplatsize.org/Successfully retrieved "https://obatambeienwasirherbal.com.parseplatkhung.org/ . count($results) . "https://obatambeienwasirherbal.com.parseplatsize.org/ scores."https://obatambeienwasirherbal.com/;// Do something with the returned ParseObject valuesfor ($i = 0; $i count($results); $i++) $object = $results<$i>; eđến $object->getObjectId() . "https://obatambeienwasirherbal.com.parseplatsize.org/ - "https://obatambeienwasirherbal.com.parseplatkhung.org/ . $object->get("https://obatambeienwasirherbal.com.parseplatkhung.org/playerName"https://obatambeienwasirherbal.com.parseplatkhung.org/);

Query Constraints

Basics

There are several ways to put constraints on the objects found by a ParseQuery. You can filter out objects with a particular key-value pair with notEqualTo:


$query->notEqualTo("https://obatambeienwasirherbal.com/playerName"https://obatambeienwasirherbal.com.parseplatkhung.org/, "https://obatambeienwasirherbal.com.parseplatsize.org/Michael Yabuti"https://obatambeienwasirherbal.com.parseplatkhung.org/);
You can give sầu multiple constraints, and objects will only be in the results if they match all of the constraints. In other words, it’s lượt thích an AND of constraints.


$query->notEqualTo("https://obatambeienwasirherbal.com/playerName"https://obatambeienwasirherbal.com.parseplatkhung.org/, "https://obatambeienwasirherbal.com.parseplatsize.org/Michael Yabuti"https://obatambeienwasirherbal.com.parseplatsize.org/);$query->greaterThan("https://obatambeienwasirherbal.com.parseplatkhung.org/playerAge"https://obatambeienwasirherbal.com.parseplatsize.org/, 18);

Limit

You can limit the number of results by setting limit. By mặc định, results are limited to lớn 100. In the old Parse hosted backkết thúc, the maximum limit was 1,000, but Parse Server removed that constraint:


$query->limit(10); // limit lớn at most 10 results

First

If you want exactly one result, a more convenient alternative may be to lớn use first instead of using find.


$query = new ParseQuery("https://obatambeienwasirherbal.com.parseplatsize.org/GameScore"https://obatambeienwasirherbal.com.parseplatsize.org/);$query->equalTo("https://obatambeienwasirherbal.com.parseplatsize.org/playerEmail"https://obatambeienwasirherbal.com.parseplatsize.org/, "https://obatambeienwasirherbal.com/"https://obatambeienwasirherbal.com.parseplatsize.org/);$object = $query->first();

Skip

You can skip the first results by setting skip. In the old Parse hosted backkết thúc, the maximum skip value was 10,000, but Parse Server removed that constraint. This can be useful for pagination:


$query->skip(10); // skip the first 10 results

With Count

If you want khổng lồ know the total number of rows in a table satisfying your query, for e.g. pagination purposes - you can use withCount.

Note: Using this feature will change the structure of response, see the example below.

Let’s say you have sầu 200 rows in a table called GameScore:


$query = new ParseQuery("https://obatambeienwasirherbal.com/GameScore"https://obatambeienwasirherbal.com.parseplatsize.org/);$query->withCount();$query->limit(25);$response = $query->find();$response<"https://obatambeienwasirherbal.com/count"https://obatambeienwasirherbal.com.parseplatkhung.org/> // Returns 200 the total number of objects dispite limit / skip$response<"https://obatambeienwasirherbal.com/results"https://obatambeienwasirherbal.com.parseplatkhung.org/> // Returns 25 objects// As of PHPhường 7.1 you can use Array Destructuring<"https://obatambeienwasirherbal.com.parseplatkhung.org/count"https://obatambeienwasirherbal.com/ => $count, "https://obatambeienwasirherbal.com/results"https://obatambeienwasirherbal.com/ => $results> = $query->find();// Use $count and $results
⚠️ Сount operations can be slow và expensive.

If you only want lớn get the count without objects - use Counting Objects.

Ascending và Descending

For sortable types lượt thích numbers and strings, you can control the order in which results are returned:


// Sorts the results in ascending order by the score field$query->ascending("https://obatambeienwasirherbal.com.parseplatkhung.org/score"https://obatambeienwasirherbal.com.parseplatsize.org/);// Sorts the results in descending order by the score field$query->descending("https://obatambeienwasirherbal.com.parseplatsize.org/score"https://obatambeienwasirherbal.com.parseplatkhung.org/);

Less than Greater than

For sortable types, you can also use comparisons in queries:


// Restricts to wins $query->lessThan("https://obatambeienwasirherbal.com/wins"https://obatambeienwasirherbal.com.parseplatsize.org/, 50);// Restricts lớn wins $query->lessThanOrEqualTo("https://obatambeienwasirherbal.com.parseplatsize.org/wins"https://obatambeienwasirherbal.com/, 50);// Restricts to wins > 50$query->greaterThan("https://obatambeienwasirherbal.com.parseplatsize.org/wins"https://obatambeienwasirherbal.com/, 50);// Restricts khổng lồ wins >= 50$query->greaterThanOrEqualTo("https://obatambeienwasirherbal.com.parseplatsize.org/wins"https://obatambeienwasirherbal.com.parseplatsize.org/, 50);

Within Polygon

For sorting by ParseGeoPoint you can query for whether an object lies within a polygon of geo points:


// construct 3 geo points$geoPoint1 = new ParseGeoPoint();$geoPoint2 = new ParseGeoPoint();$geoPoint3 = new ParseGeoPoint();// restrict to any objects where `myGeoPoint` lies within a polygon made by 3 or more geo points$query->withinPolygon("https://obatambeienwasirherbal.com.parseplatsize.org/myGeoPoint"https://obatambeienwasirherbal.com.parseplatkhung.org/, <$geoPoint1, $geoPoint2, $geoPoint3>);

Contained In

If you want to retrieve objects matching several different values, you can use containedIn, providing an array of acceptable values. This is often useful to replace multiple queries with a single query. For example, if you want to retrieve sầu scores made by any player in a particular array:


// Finds scores from any of Jonathan, Dario, or Shawn$query->containedIn("https://obatambeienwasirherbal.com.parseplatkhung.org/playerName"https://obatambeienwasirherbal.com.parseplatsize.org/, <"https://obatambeienwasirherbal.com.parseplatsize.org/Jonathan Walsh"https://obatambeienwasirherbal.com/, "https://obatambeienwasirherbal.com.parseplatkhung.org/Dario Wunsch"https://obatambeienwasirherbal.com.parseplatkhung.org/, "https://obatambeienwasirherbal.com.parseplatkhung.org/Shawn Simon"https://obatambeienwasirherbal.com/>);
If you want to retrieve objects that vị not match any of several values you can use notContainedIn, providing an array of acceptable values. For example if you want to retrieve sầu scores from players besides those in an array:


// Finds scores from anyone who is neither Jonathan, Dario, nor Shawn$query->notContainedIn("https://obatambeienwasirherbal.com.parseplatsize.org/playerName"https://obatambeienwasirherbal.com/, <"https://obatambeienwasirherbal.com/Jonathan Walsh"https://obatambeienwasirherbal.com/, "https://obatambeienwasirherbal.com.parseplatkhung.org/Dario Wunsch"https://obatambeienwasirherbal.com/, "https://obatambeienwasirherbal.com.parseplatkhung.org/Shawn Simon"https://obatambeienwasirherbal.com/>);

Exists

If you want lớn retrieve sầu objects that have a particular key mix, you can use exists. Conversely, if you want lớn retrieve sầu objects without a particular key mix, you can use doesNotExist.


// Finds objects that have sầu the score set$query->exists("https://obatambeienwasirherbal.com/score"https://obatambeienwasirherbal.com.parseplatsize.org/);// Finds objects that don"https://obatambeienwasirherbal.com.parseplatsize.org/t have sầu the score set$query->doesNotExist("https://obatambeienwasirherbal.com.parseplatsize.org/score"https://obatambeienwasirherbal.com.parseplatsize.org/);

Matches Key in Query

You can use the matchesKeyInQuery method to lớn get objects where a key matches the value of a key in a mix of objects resulting from another query. For example, if you have sầu a class containing sports teams và you store a user’s hometown in the user class, you can issue one query lớn find the array of users whose hometown teams have winning records. The query would look like:


$teamQuery = new ParseQuery("https://obatambeienwasirherbal.com/Team"https://obatambeienwasirherbal.com.parseplatkhung.org/);$teamQuery->greaterThan("https://obatambeienwasirherbal.com.parseplatkhung.org/winPct"https://obatambeienwasirherbal.com.parseplatkhung.org/, 0.5);$userQuery = ParseUser::query();$userQuery->matchesKeyInQuery("https://obatambeienwasirherbal.com.parseplatsize.org/hometown"https://obatambeienwasirherbal.com.parseplatsize.org/, "https://obatambeienwasirherbal.com.parseplatsize.org/city"https://obatambeienwasirherbal.com/, $teamQuery);$results = $userQuery->find();// results has the array of users with a hometown team with a winning record
Conversely, to lớn get objects where a key does not match the value of a key in a set of objects resulting from another query, use doesNotMatchKeyInQuery. For example, khổng lồ find users whose hometown teams have losing records:


$losingUserQuery = ParseUser::query();$losingUserQuery->doesNotMatchKeyInQuery("https://obatambeienwasirherbal.com.parseplatkhung.org/hometown"https://obatambeienwasirherbal.com/, "https://obatambeienwasirherbal.com/city"https://obatambeienwasirherbal.com/, teamQuery);$results = $losingUserQuery->find();// results has the array of users with a hometown team with a losing record

Select

To filter rows based on objectId’s from pointers in a second table, you can use dot notation:


$rolesOfTypeX = new ParseQuery("https://obatambeienwasirherbal.com.parseplatsize.org/Role"https://obatambeienwasirherbal.com.parseplatsize.org/);$rolesOfTypeX->equalTo("https://obatambeienwasirherbal.com/type"https://obatambeienwasirherbal.com.parseplatkhung.org/, "https://obatambeienwasirherbal.com.parseplatkhung.org/x"https://obatambeienwasirherbal.com.parseplatsize.org/);$groupsWithRoleX = new ParseQuery("https://obatambeienwasirherbal.com.parseplatsize.org/Group"https://obatambeienwasirherbal.com.parseplatkhung.org/);$groupsWithRoleX->matchesKeyInQuery("https://obatambeienwasirherbal.com.parseplatkhung.org/objectId"https://obatambeienwasirherbal.com.parseplatsize.org/, "https://obatambeienwasirherbal.com.parseplatkhung.org/belongsTo.objectId"https://obatambeienwasirherbal.com/, rolesOfTypeX);$results = $groupsWithRoleX->find();// results has the các mục of groups with role x
You can restrict the fields returned by calling select with an array of keys. To retrieve documents that contain only the score và playerName fields (và also special built-in fields such as objectId, createdAt, and updatedAt):


$query = new ParseQuery("https://obatambeienwasirherbal.com.parseplatsize.org/GameScore"https://obatambeienwasirherbal.com.parseplatkhung.org/);$query->select(<"https://obatambeienwasirherbal.com.parseplatkhung.org/score"https://obatambeienwasirherbal.com.parseplatsize.org/, "https://obatambeienwasirherbal.com.parseplatsize.org/playerName"https://obatambeienwasirherbal.com.parseplatkhung.org/>);$results = $query->find();// each of results will only have sầu the selected fields available.
The remaining fields can be fetched later by calling fetch on the returned objects:


$result = $query->first();// only the selected fields of the object will now be available here.$result->fetch();// all fields of the object will now be available here.

Aggregate

Queries can be made using aggregates, allowing you lớn retrieve sầu objects over a set of đầu vào values. cảnh báo that the MasterKey is Required.

For a menu of available operators please refer lớn Mongo Aggregate Documentation.


// group pipeline is similar khổng lồ distinct, can apply $sum, $avg, $max, $min// accumulate sum and store in total field$pipeline = < "https://obatambeienwasirherbal.com.parseplatsize.org/group"https://obatambeienwasirherbal.com.parseplatkhung.org/ => < "https://obatambeienwasirherbal.com.parseplatsize.org/objectId"https://obatambeienwasirherbal.com.parseplatkhung.org/ => null, "https://obatambeienwasirherbal.com/total"https://obatambeienwasirherbal.com.parseplatsize.org/ => < "https://obatambeienwasirherbal.com.parseplatsize.org/$sum"https://obatambeienwasirherbal.com/ => "https://obatambeienwasirherbal.com.parseplatkhung.org/$score"https://obatambeienwasirherbal.com.parseplatkhung.org/> >>;$results = $query->aggregate($pipeline);// project pipeline is similar to lớn keys, add or remove existing fields// includes name key$pipeline = < "https://obatambeienwasirherbal.com.parseplatsize.org/project"https://obatambeienwasirherbal.com.parseplatkhung.org/ => < "https://obatambeienwasirherbal.com.parseplatsize.org/name"https://obatambeienwasirherbal.com.parseplatsize.org/ => 1 >>;$results = $query->aggregate($pipeline);// match pipeline is similar to lớn equalTo// filter out objects with score greater than 15 $pipeline = < "https://obatambeienwasirherbal.com/match"https://obatambeienwasirherbal.com/ => < "https://obatambeienwasirherbal.com.parseplatsize.org/score"https://obatambeienwasirherbal.com/ => < "https://obatambeienwasirherbal.com.parseplatsize.org/$gt"https://obatambeienwasirherbal.com.parseplatsize.org/ => 15 > >>;$results = $query->aggregate($pipeline);

Distinct

Queries can be made using distinct, allowing you find quality values for a specified field.Keep in mind that the MasterKey is required.


// finds score that are unique$results = $query->distinct("https://obatambeienwasirherbal.com.parseplatkhung.org/score"https://obatambeienwasirherbal.com/);// can be used with equalTo$query = new ParseQuery("https://obatambeienwasirherbal.com.parseplatsize.org/TestObject"https://obatambeienwasirherbal.com/);$query->equalTo("https://obatambeienwasirherbal.com.parseplatkhung.org/name"https://obatambeienwasirherbal.com.parseplatkhung.org/, "https://obatambeienwasirherbal.com.parseplatsize.org/foo"https://obatambeienwasirherbal.com.parseplatsize.org/);$results = $query->distinct("https://obatambeienwasirherbal.com/score"https://obatambeienwasirherbal.com.parseplatkhung.org/);

Relative Time

Queries can be made using relative time, allowing you to retrieve objects over a varying ranges of relative sầu dates. Keep in mind that all relative queries are performed using the server’s time & timezone.


// greater than 2 weeks ago$query->greaterThanRelativeTime("https://obatambeienwasirherbal.com/createdAt"https://obatambeienwasirherbal.com.parseplatkhung.org/, "https://obatambeienwasirherbal.com/2 weeks ago"https://obatambeienwasirherbal.com/);// less than 1 day in the future$query->lessThanRelativeTime("https://obatambeienwasirherbal.com/updatedAt"https://obatambeienwasirherbal.com.parseplatkhung.org/, "https://obatambeienwasirherbal.com/in 1 day"https://obatambeienwasirherbal.com.parseplatsize.org/);// can make queries to lớn very specific points in time$query->greaterThanOrEqualToRelativeTime("https://obatambeienwasirherbal.com.parseplatkhung.org/createdAt"https://obatambeienwasirherbal.com/, "https://obatambeienwasirherbal.com/1 year 2 weeks 30 days 2 hours 5 minutes 10 seconds ago"https://obatambeienwasirherbal.com.parseplatkhung.org/);// can make queries based on right now// gets everything updated up khổng lồ this point in time$query->lessThanOrEqualToRelativeTime("https://obatambeienwasirherbal.com.parseplatkhung.org/updatedAt"https://obatambeienwasirherbal.com.parseplatsize.org/, "https://obatambeienwasirherbal.com/now"https://obatambeienwasirherbal.com/);// shorthvà keywords work as well$query->greaterThanRelativeTime("https://obatambeienwasirherbal.com/date"https://obatambeienwasirherbal.com.parseplatsize.org/, "https://obatambeienwasirherbal.com.parseplatkhung.org/1 yr 2 wks 30 d 2 hrs 5 mins 10 secs ago"https://obatambeienwasirherbal.com.parseplatkhung.org/);

Queries on Array Values

For keys with an array type, you can find objects where the key’s array value contains 2 by:


// Find objects where the array in arrayKey contains 2.$query->equalTo("https://obatambeienwasirherbal.com.parseplatkhung.org/arrayKey"https://obatambeienwasirherbal.com.parseplatkhung.org/, 2);
You can also find objects where the key’s array value contains each of the elements 2, 3, & 4 with the following:


// Find objects where the array in arrayKey contains all of the elements 2, 3, and 4.$query->containsAll("https://obatambeienwasirherbal.com.parseplatsize.org/arrayKey"https://obatambeienwasirherbal.com.parseplatsize.org/, <2, 3, 4>);

Queries on String Values

Use startsWith lớn restrict to string values that start with a particular string. Similar khổng lồ a MySquốc lộ LIKE operator, this is indexed so it is efficient for large datasets:


// Finds barbecue sauces that start with "https://obatambeienwasirherbal.com.parseplatsize.org/Big Daddy"https://obatambeienwasirherbal.com.parseplatkhung.org/s"https://obatambeienwasirherbal.com.parseplatsize.org/.$query = new ParseQuery("https://obatambeienwasirherbal.com.parseplatsize.org/BarbecueSauce"https://obatambeienwasirherbal.com.parseplatkhung.org/);$query->startsWith("https://obatambeienwasirherbal.com/name"https://obatambeienwasirherbal.com.parseplatkhung.org/, "https://obatambeienwasirherbal.com.parseplatkhung.org/Big Daddy"https://obatambeienwasirherbal.com.parseplatkhung.org/s"https://obatambeienwasirherbal.com/);
The above example will match any BarbecueSauce objects where the value in the “name” String key starts with “Big Daddy’s”. For example, both “Big Daddy’s” & “Big Daddy’s BBQ” will match, but “big daddy’s” or “BBQ Sauce: Big Daddy’s” will not.

You may also use endsWith khổng lồ restrict to lớn string values that over with a particular string instead:


// Finds barbecue sauces that kết thúc with "https://obatambeienwasirherbal.com/Sauce"https://obatambeienwasirherbal.com/.$query = new ParseQuery("https://obatambeienwasirherbal.com/BarbecueSauce"https://obatambeienwasirherbal.com/);$query->endsWith("https://obatambeienwasirherbal.com.parseplatkhung.org/name"https://obatambeienwasirherbal.com.parseplatsize.org/, "https://obatambeienwasirherbal.com.parseplatsize.org/Sauce"https://obatambeienwasirherbal.com/);
The above sầu example will match any BarbecueSauce objects where the value in the “name” String key ends with “Sauce”. For example, both “Big Daddy’s BBQ Sauce” and “Home Style BBQ Sauce” will match, but “Big Daddy’s BBQ” or “Best Sauce: Big Daddy’s” will not.

Queries that have sầu regular expression constraints are very expensive sầu, especially for classes with over 100,000 records. Parse restricts how many such operations can be run on a particular app at any given time.

Relational Queries

There are several ways to issue queries for relational data. If you want to retrieve objects where a field matches a particular ParseObject, you can use equalTo just lượt thích for other data types. For example, if each Comment has a Post object in its post field, you can fetch comments for a particular Post:


// Assume ParseObject $myPost was previously created.$query = new ParseQuery("https://obatambeienwasirherbal.com.parseplatsize.org/Comment"https://obatambeienwasirherbal.com.parseplatsize.org/);$query->equalTo("https://obatambeienwasirherbal.com.parseplatkhung.org/post"https://obatambeienwasirherbal.com/, $myPost);$comments = $query->find();// comments now contains the comments for myPost
If you want lớn retrieve sầu objects where a field contains a ParseObject that matches a different query, you can use matchesQuery. In order khổng lồ find comments for posts containing images, you can do:


$innerQuery = new ParseQuery("https://obatambeienwasirherbal.com.parseplatkhung.org/Post"https://obatambeienwasirherbal.com.parseplatsize.org/);$innerQuery->exists("https://obatambeienwasirherbal.com.parseplatsize.org/image"https://obatambeienwasirherbal.com.parseplatkhung.org/);$query = new ParseQuery("https://obatambeienwasirherbal.com.parseplatsize.org/Comment"https://obatambeienwasirherbal.com/);$query->matchesQuery("https://obatambeienwasirherbal.com/post"https://obatambeienwasirherbal.com/, $innerQuery);$comments = $query->find();// comments now contains the comments for posts with images.
If you want lớn retrieve sầu objects where a field contains a ParseObject that does not match a different query, you can use doesNotMatchQuery. In order lớn find comments for posts without images, you can do:


$innerQuery = new ParseQuery("https://obatambeienwasirherbal.com.parseplatsize.org/Post"https://obatambeienwasirherbal.com.parseplatkhung.org/);$innerQuery->exists("https://obatambeienwasirherbal.com.parseplatsize.org/image"https://obatambeienwasirherbal.com/);$query = new ParseQuery("https://obatambeienwasirherbal.com/Comment"https://obatambeienwasirherbal.com.parseplatsize.org/);$query->doesNotMatchQuery("https://obatambeienwasirherbal.com/post"https://obatambeienwasirherbal.com/, $innerQuery);$query->find();// comments now contains the comments for posts without images.
You can also vày relational queries by objectId:


$post = new ParseObject("https://obatambeienwasirherbal.com.parseplatsize.org/Post"https://obatambeienwasirherbal.com/, "https://obatambeienwasirherbal.com.parseplatsize.org/1zEcyElZ80"https://obatambeienwasirherbal.com.parseplatsize.org/);$query->equalTo("https://obatambeienwasirherbal.com/post"https://obatambeienwasirherbal.com/, $post);
In some situations, you want khổng lồ return multiple types of related objects in one query. You can vì chưng this with the include method. For example, let’s say you are retrieving the last ten comments, & you want to retrieve their related posts at the same time:


$query = new ParseQuery("https://obatambeienwasirherbal.com.parseplatsize.org/Comment"https://obatambeienwasirherbal.com.parseplatsize.org/);// Retrieve the most recent onesquery->descending("https://obatambeienwasirherbal.com/createdAt"https://obatambeienwasirherbal.com.parseplatsize.org/);// Only retrieve the last tenquery->limit(10);// Include the post data with each commentquery->includeKey("https://obatambeienwasirherbal.com/post"https://obatambeienwasirherbal.com.parseplatkhung.org/);$comments = query->find();// Comments now contains the last ten comments, và the "https://obatambeienwasirherbal.com/post"https://obatambeienwasirherbal.com.parseplatsize.org/ field// has been populated. For example:for ($i = 0; $i count($comments); $i++) // This does not require a network access. $post = $comments<$i>->get("https://obatambeienwasirherbal.com/post"https://obatambeienwasirherbal.com/);
You can also vị multi level includes using dot notation. If you wanted to include the post for a bình luận and the post’s author as well you can do:


$query->includeKey("https://obatambeienwasirherbal.com.parseplatsize.org/post.author"https://obatambeienwasirherbal.com.parseplatsize.org/);
You can issue a query with multiple fields included by calling includeKey multiple times. This functionality also works with ParseQuery helpers lượt thích first và get.

Counting Objects

Note: In the old Parse hosted backover, count queries were rate limited to lớn a maximum of 160 requests per minute. They also returned inaccurate results for classes with more than 1,000 objects. But, Parse Server has removed both constraints & can count objects well above 1,000.

If you just need to count how many objects match a query, but you vì chưng not need to lớn retrieve all the objects that match, you can use count instead of find. For example, khổng lồ count how many games have sầu been played by a particular player:


$query = new ParseQuery("https://obatambeienwasirherbal.com.parseplatkhung.org/GameScore"https://obatambeienwasirherbal.com.parseplatkhung.org/);$query->equalTo("https://obatambeienwasirherbal.com.parseplatkhung.org/playerName"https://obatambeienwasirherbal.com/, "https://obatambeienwasirherbal.com.parseplatsize.org/Sean Plott"https://obatambeienwasirherbal.com/);$count = $query->count();// The count request succeeded. Show the countecho "https://obatambeienwasirherbal.com.parseplatsize.org/Sean has played "https://obatambeienwasirherbal.com.parseplatkhung.org/ . $count . "https://obatambeienwasirherbal.com.parseplatsize.org/ games"https://obatambeienwasirherbal.com.parseplatkhung.org/;

Compound Queries

If you want khổng lồ find objects that match one of several queries, you can use ParseQuery.or method khổng lồ construct a query that is an OR of the queries passed in. For instance if you want khổng lồ find players who either have sầu a lot of wins or a few wins, you can do:


$lotsOfWins = new ParseQuery("https://obatambeienwasirherbal.com/Player"https://obatambeienwasirherbal.com.parseplatsize.org/);$lotsOfWins->greaterThan("https://obatambeienwasirherbal.com.parseplatkhung.org/wins"https://obatambeienwasirherbal.com.parseplatsize.org/, 150);$fewWins = new ParseQuery("https://obatambeienwasirherbal.com.parseplatkhung.org/Player"https://obatambeienwasirherbal.com/);$fewWins->lessThan("https://obatambeienwasirherbal.com.parseplatkhung.org/wins"https://obatambeienwasirherbal.com.parseplatkhung.org/, 5);$mainQuery = ParseQuery::orQueries(<$lotsOfWins, $fewWins>);$results = $mainQuery->find();// results contains an array of players that either have won a lot of games or won only a few games.
You can add additional constraints lớn the newly created ParseQuery that act as an ‘and’ operator.

cảnh báo that we vì chưng not, however, tư vấn GeoPoint or non-filtering constraints (e.g. near, withinGeoBox, limit, skip, ascending/descending, includeKey) in the subqueries of the compound query.

Each ParseObject is an instance of a specific subclass with a class name that you can use khổng lồ distinguish different sorts of data. For example, we could Điện thoại tư vấn the high score object a GameScore. We recommend that you NameYourClassesLikeThis & nameYourKeysLikeThis, just to lớn keep your code looking pretty.

To create a new subclass, create a new class which extends the ParseObject class, add the $parseClassName static property, and Hotline the registerSubclass method before use. Any ParseQuery will return instances of the new class for any ParseObject with the same class name.


class GameScore extends ParseObject public static $parseClassName = "https://obatambeienwasirherbal.com.parseplatsize.org/GameScore"https://obatambeienwasirherbal.com.parseplatkhung.org/;
// Do this once, at the start of your app, before ParseClient::initialize(...);GameScore::registerSubclass();// Create a new instance of that class.$gameScore = new GameScore();
You can add additional methods & properties to your subclasses of ParseObject.


// A complex subclass of ParseObjectclass Monster extends ParseObject public static $parseClassName = "https://obatambeienwasirherbal.com/Monster"https://obatambeienwasirherbal.com.parseplatkhung.org/; public function hasSuperHumanStrength() return this->get("https://obatambeienwasirherbal.com.parseplatsize.org/strength"https://obatambeienwasirherbal.com.parseplatkhung.org/) > 18; public static function spawn($strength) $quái dị = new Monster(); $monster->set("https://obatambeienwasirherbal.com/strength"https://obatambeienwasirherbal.com.parseplatkhung.org/, $strength); return $monster;
$monster = Monster::spawn(200);emang lại monster->strength(); // Displays 200.emang lại monster->hasSuperHumanStrength(); // Displays true.

Read Preference

When using a MongoDB replica phối, you can use the $query->readPreference(readPreference, includeReadPreference, subqueryReadPreference) function lớn choose from which replica the objects will be retrieved. The includeReadPreference argument chooses from which replica the included pointers will be retrieved and the subqueryReadPreference argument chooses in which replica the subqueries will run. The possible values are PRIMARY (default), PRIMARY_PREFERRED, SECONDARY, SECONDARY_PREFERRED, or NEAREST. If the includeReadPreference argument is not passed, the same replica chosen for readPreference will be also used for the includes. The same rule applies for the subqueryReadPreference argument.


$query->readPreference( "https://obatambeienwasirherbal.com.parseplatkhung.org/SECONDARY"https://obatambeienwasirherbal.com.parseplatkhung.org/, "https://obatambeienwasirherbal.com.parseplatkhung.org/SECONDARY_PREFERRED"https://obatambeienwasirherbal.com/, "https://obatambeienwasirherbal.com.parseplatkhung.org/NEAREST"https://obatambeienwasirherbal.com/);
Want to lớn contribute lớn this doc? Edit this section.
UsersAt the core of many apps, there is a notion of user accounts that lets users access their information in a secure manner. We provide a specialized user class called ParseUser that automatically handles much of the functionality required for user tài khoản management.

With this class, you’ll be able to lớn add user account functionality in your app.

ParseUser is a subclass of ParseObject, & has all the same features, such as flexible schema, automatic persistence, and a key value interface. All the methods that are on ParseObject also exist in ParseUser. The difference is that ParseUser has some special additions specific khổng lồ user accounts.

ParseUser Properties

ParseUser has several values that set it apart from ParseObject:

We’ll go through each of these in detail as we run through the various use cases for users.

Signing Up

The first thing your ứng dụng will bởi is probably ask the user lớn sign up. The following code illustrates a typical sign up:


$user = new ParseUser();$user->set("https://obatambeienwasirherbal.com.parseplatkhung.org/username"https://obatambeienwasirherbal.com.parseplatsize.org/, "https://obatambeienwasirherbal.com/my name"https://obatambeienwasirherbal.com.parseplatkhung.org/);$user->set("https://obatambeienwasirherbal.com.parseplatkhung.org/password"https://obatambeienwasirherbal.com.parseplatkhung.org/, "https://obatambeienwasirherbal.com/my pass"https://obatambeienwasirherbal.com.parseplatsize.org/);$user->set("https://obatambeienwasirherbal.com.parseplatkhung.org/email"https://obatambeienwasirherbal.com.parseplatkhung.org/, "https://obatambeienwasirherbal.com.parseplatkhung.org/"https://obatambeienwasirherbal.com.parseplatkhung.org/);// other fields can be set just like with ParseObject$user->set("https://obatambeienwasirherbal.com/phone"https://obatambeienwasirherbal.com/, "https://obatambeienwasirherbal.com/415-392-0202"https://obatambeienwasirherbal.com/);try $user->signUp(); // Hooray! Let them use the ứng dụng now. catch (ParseException $ex) // Show the error message somewhere và let the user try again. eđến "https://obatambeienwasirherbal.com.parseplatsize.org/Error: "https://obatambeienwasirherbal.com/ . $ex->getCode() . "https://obatambeienwasirherbal.com/ "https://obatambeienwasirherbal.com.parseplatsize.org/ . $ex->getMessage();
This hotline will asynchronously create a new user in your Parse App. Before it does this, it also checks to make sure that both the username & email are quality. Also, it securely hashes the password in the cloud using bcrypt. We never store passwords in plaintext, nor will we ever transmit passwords back to the client in plaintext.

lưu ý that we used the signUp method, not the save sầu method. New ParseUsers should always be created using the signUp method. Subsequent updates khổng lồ a user can be done by calling save sầu.

If a signup isn’t successful, you should read the error object that is returned. The most likely case is that the username or gmail has already been taken by another user. You should clearly communicate this to lớn your users, and ask them try a different username.

You are không lấy phí khổng lồ use an tin nhắn address as the username. Simply ask your users khổng lồ enter their gmail, but fill it in the username property — ParseUser will work as normal. We’ll go over how this is handled in the rephối password section.

Logging In

Of course, after you allow users lớn sign up, you need lớn let them log in lớn their tài khoản in the future. To vì this, you can use the class method logIn.


try $user = ParseUser::logIn("https://obatambeienwasirherbal.com.parseplatkhung.org/myname"https://obatambeienwasirherbal.com/, "https://obatambeienwasirherbal.com/mypass"https://obatambeienwasirherbal.com/); // Do stuff after successful login. catch (ParseException $error) // The login failed. Check error to lớn see why.

Verifying Emails

Enabling email verification in an application’s settings allows the application to lớn reserve part of its experience for users with confirmed email addresses. Thư điện tử verification adds the emailVerified key khổng lồ the ParseUser object. When a ParseUser’s gmail is phối or modified, emailVerified is ph