Jump to content

Change user role not working


cybromancy
 Share

Recommended Posts

Hi there, going a bit crazy here. Trying to be a user and change the role of another user.

//get the user id to change

$changeRole = $users->get($sanitizer->username('username'))->id;

//add role

$changeRole->addRole('moderator');

//save changes

$users->save($changeRole);

 

What am I missing? Is it a user permissions setting? All I saw were permission settings for pages.

Thanks up front for the help.

Link to comment
Share on other sites

thanks for the reply I changed my code, but it's still throwing an error

$changeRole = $users->get($sanitizer->username('username'));
//add role
$changeRole->addRole('moderator');
//save changes
$users->save($changeRole);

Do I need to be using:

    $users->of(true);

or

  $changeRole>roles->add($roles->get('moderator));

Link to comment
Share on other sites

3 minutes ago, cybromancy said:

thanks for the reply I changed my code, but it's still throwing an error


$changeRole = $users->get($sanitizer->username('username'));
//add role
$changeRole->addRole('moderator');
//save changes
$users->save($changeRole);

Do I need to be using:

    $users->of(true);

or

  $changeRole>roles->add($roles->get('moderator));

Yeah, you will need something like this:

$u = $users->get($sanitizer->username('username'));
$u->of(false);
$u->addRole("moderator");
$u->save();

You should have received an error that mentions specifically that you need to turn of output formatting. Do you have debugmode on and/or TracyDebugger installed?

  • Like 2
Link to comment
Share on other sites

That was it THANKS.

I got this as an error:

Call $page->setOutputFormatting(false) before getting/setting values that will be modified and saved.

Is that what the 'of' stands for in of(false) ? outputformatting?

Call $page->setOutputFormatting(false) before getting/setting values that will be modified and saved.

  • Like 1
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

×
×
  • Create New...