Search code examples
phpparse-server

Create ParseUser from logged user in php


I'm having problems when I've tried to create new ParseUsers from a logged user using ParseUser. I'm getting this error:

Fatal error: Uncaught exception 'Exception' with message 'Tried to save a batch with a cycle.' in /var/www/html/test/vendor/parse/php-sdk/src/Parse/ParseObject.php:1019

            session_start();
            ParseClient::setStorage( new ParseSessionStorage() );
            $user=new ParseUser();
            $user->set("username",$user);
            $user->set("password",$password);
            $user->set("email",$email);
            try{
                $user->signUp();
            }catch(ParseException $exception){
                print_r($exception);
            }

Solution

  • the problem is in the following row:

    $user->set("username",$user);
    

    Your user object cannot be a username. Your username should be a string (it can be an email or some string that you receive by your users). This line of code will not work even if you will set the $user into another field (and not as the username) the reason is because you are trying to save a relation to the same object that you are trying to create so the server telling you that it is an infinite loop and anyway there is no reason to do it. so what you need to do is:

    1. Use string in your username field
    2. Use logged in user as a relationship of other objects