Jump to content

new user outside pw folder


Frank Vèssia
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

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...