Skip to content

Instantly share code, notes, and snippets.

@niraj-shah
Last active December 21, 2015 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niraj-shah/6221502 to your computer and use it in GitHub Desktop.
Save niraj-shah/6221502 to your computer and use it in GitHub Desktop.
Usefull Parse.com PHP Functions
<?php
require_once( 'parse/parse.php' );
// Login to parse
$parseLogin = new parseUser();
$parseLogin->username = 'username';
$parseLogin->password = 'password';
try {
$result = $parseLogin->login();
if ( $result ) {
// success, set cookie
echo 'Login successful';
} else {
// display error
echo 'Login error';
}
} catch ( Exception $e ) {
echo 'Login error: ' . $e;
}
// Save to custom class
$parse = new parseObject('CustomClassName');
$parse->foo = "bar";
$result = $parse->save();
print_r( $result );
// Get from default User class
$parseGet = new parseObject('_User');
$result = $parseGet->get( 'objectId' );
print_r( $result );
// Get from custom class
$parseGet = new parseObject('CustomClassName');
$result = $parseGet->get( 'objectId' );
print_r( $result );
// Find from default User class
$parseQuery = new parseQuery('_User');
$parseQuery->where('name', 'Niraj Shah');
$result = $parseQuery->find();
print_r( $result );
// Find from custom class
$parseQuery = new parseQuery('CustomClassName');
$parseQuery->where('foo', 'bar');
$result = $parseQuery->find();
print_r( $result );
// Update row in custom class
$parseUpdate = new parseObject('CustomClassName');
$parseUpdate->foo = "foo";
$result = $parseUpdate->update( '0rYHj1Wtzu' );
print_r( $result );
// Delete from custom class
$parseDelete = new parseObject('CustomClassName');
$result = $parseDelete->delete( 'objectId' );
print_r( $result );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment