Jump to content

Creating new user, can't save page 0


Manaus
 Share

Recommended Posts

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 not
saveable (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

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 by sakkoulas
  • Like 1
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...