Jim 007
Jim 007

Reputation: 310

How to load Parse PHP Classses in a simple module Drupal?

I tried to use the Parse.com PHP SDK inside a (simple !) Drupal module to send Push notification, but Drupal don't load Parse SDK Classes. I've got PHP error :

PHP Fatal error:  Class 'ParseClient' not found 

My files are :

push.module
push.info
parse_sdk/autoload.php
parse_sdk/ (and all files from https://github.com/ParsePlatform/parse-php-sdk)

And in the file push.module :

use Parse\ParseClient;
require_once('parse_sdk/autoload.php');
ParseClient::initialize( $app_id, $rest_key, $master_key );

What's wrong with my code ??? Thanks for your help.

Actually it's working with REST API, but I can't get it with PHP SDK. I even tried to insert "files[] = parse_sdk/src/Parse/ParsePush.php" in push.info, wihtout success.

Upvotes: 0

Views: 655

Answers (2)

NickUnuchek
NickUnuchek

Reputation: 12857

  1. Download PARSE_PHP_SDK from here
  2. Unzip it to folder .../root/parse_sdk/
  3. Create a php file in .../root/ (for ex. .../root/example.php)
  4. Write it in the php file:
<?php
namespace Parse;
require_once('parse_sdk/autoload.php');
$url = 'https://api.parse.com/1/push';
$app_id = 'YOUR_app_id';
$rest_key = 'YOUR_rest_key ';
$master_key = 'YOUR_master_key ';
ParseClient::initialize( $app_id, $rest_key, $master_key );
//YOUR OTHER CODE
?>

Upvotes: 0

Jim 007
Jim 007

Reputation: 310

Ok, this my answer :

require_once('parse_sdk/autoload.php');
\Parse\ParseClient::initialize( $app_id, $rest_key, $master_key );

Juste add "\Parse\" and it's work ;-)

Upvotes: 2

Related Questions