Frank Vèssia Posted September 27, 2011 Posted September 27, 2011 I always "fight" with wire method, this time i need to create a new user outside PW root folder. $name = wire('sanitizer')->username(wire('input')->post->login_name); $pass = wire('input')->post->login_pass; $email = wire('sanitizer')->email(wire('input')->post->email); $u = new User(); $u->name = $name; $u->pass = $pass; $u->addRole("guest"); $u->save(); i get error on addRole(), i need to add wire at some point but i don't know where.
apeisa Posted September 27, 2011 Posted September 27, 2011 Are you running 2.1 but not the latest commit? addUser() was added to 2.1 about week ago: http://processwire.com/talk/index.php/topic,509.0.html
apeisa Posted September 27, 2011 Posted September 27, 2011 Also not sure if you need to add "quest" role or is it added automatically.
Frank Vèssia Posted September 27, 2011 Author Posted September 27, 2011 Thanks Apeisa, i run 2.1 lc but didn't notice that post...
ryan Posted September 27, 2011 Posted September 27, 2011 If you aren't running the latest 2.1, you can also do this: <?php $role = $roles->get('role_name'); $user->roles->add($role); Also, to make your code more readable and easier to type, I would suggest localizing the API vars you are using, like this: <?php $input = wire('input'); $sanitizer = wire('sanitizer'); That way you can use them like you would in a template.
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