Manaus Posted November 27, 2013 Share Posted November 27, 2013 Hello, I'm trying to create a new user from the API, this is my code: $u = $users->add($csvnome); $u->save(); $u->of(false); // $u->save(); $u->azienda = $csvazienda; $u->pass = $csvpass; $u->email = $csvemail; $u->nome = $csvnome; $u->save(); $u->addRole("utente"); $u->save(); $u->of(true); I get this error: Error: Exception: Can't save page 0: : Pages of type NullPage are notsaveable (in /Users/utente/Sites/gammapw/wire/core/Pages.php line 514) I suppose this is not the right way to create a new user? Thanks!! Link to comment Share on other sites More sharing options...
sakkoulas Posted November 27, 2013 Share Posted November 27, 2013 (edited) hi manaus try this $u = new User(); $u->of(false); $u->name = $name; $u->email = $email $u->pass = $password; $u->addRole("UserRole"); $u->save(); $u->of(true); you can read here http://processwire.com/talk/topic/3543-register-users-and-add-page-same-as-username/#entry34822 Edited November 27, 2013 by sakkoulas 1 Link to comment Share on other sites More sharing options...
Manaus Posted November 27, 2013 Author Share Posted November 27, 2013 Great, thanks!!! Link to comment Share on other sites More sharing options...
ryan Posted November 30, 2013 Share Posted November 30, 2013 Actually either syntax should work here. The $users->add('name'); function is a valid way to create a new user. Though the $u->of(); and $u->save(); immediately after your add() aren't necessary. The $users->add() syntax is newer though, so may not be present in past versions of PW. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now