2016-06-20 20 views
2

當我嘗試使用Parse.com PHP SDK它 錯誤是「帳戶已存在此用戶名」Parse.com PHP異常顯示的所有錯誤

但它拋出所有這些錯誤消息到運行PHP代碼:

Fatal error: Uncaught exception 'Parse\ParseException' with message 'Account already exists for this username' in /Users/yousef/Desktop/project/vendor/parse/php-sdk/src/Parse/ParseClient.php:357 Stack trace: #0 /Users/yousef/Desktop/project/vendor/parse/php-sdk/src/Parse/ParseObject.php(1038): Parse\ParseClient::_request('POST', 'classes/_User', NULL, '{"username":"my...', false) #1 /Users/yousef/Desktop/project/vendor/parse/php-sdk/src/Parse/ParseObject.php(947): Parse\ParseObject::deepSave(Object(Parse\ParseUser), false) #2 /Users/yousef/Desktop/project/vendor/parse/php-sdk/src/Parse/ParseUser.php(108): Parse\ParseObject->save() #3 /Users/yousef/Desktop/project/test.php(20): Parse\ParseUser->signUp() #4 {main} thrown in /Users/yousef/Desktop/project/vendor/parse/php-sdk/src/Parse/ParseClient.php on line 357 

代碼中,我使用

<?php 

require 'vendor/autoload.php'; 

use Parse\ParseClient; 

ParseClient::initialize('YousefId', '', 'YousefMaster'); 
ParseClient::setServerURL('server-ip:1337/parse'); 


use Parse\ParseUser; 

$user = new ParseUser(); 
$user->set("username", "my name"); 
$user->set("password", "my pass"); 
$user->set("email", "[email protected]"); 
$user->set("phone", "415-392-0202"); 

try { 
    $user->signUp(); 
} catch (ParseException $error) { 
    echo $error->getCode(); 
    echo $error->getMessage(); 
} 

?> 

讓我怎麼只顯示而不是顯示所有這些錯誤的錯誤代碼和消息。

回答

1

您需要參考Parse命名空間中的ParseException

嘗試

catch (Parse\ParseException $error) { 
    // ... 
} 
+0

還是同樣的問題,我不認爲這是問題,因爲在[Github上(https://github.com/ParsePlatform/parse-php-sdk)解析像我一樣使用PHP SDK。 – T3lemi

+0

哦,對不起,它工作我在我的代碼中輸入錯了,所以是你的代碼工作正常,這讓我想知道爲什麼在Github上說不同。 – T3lemi

+0

我在5分鐘內接受您的答案,謝謝! – T3lemi