Jump to content

Recommended Posts

Posted

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.

Posted

Hi @cybromancy - welcome to the forums!

You are assigning the user's ID to the $changeRole variable. You need to keep the full user object assigned to it so that addRole() can do its thing!

Let us know if you have anymore troubles.

Posted

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));

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

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
Posted
Just now, cybromancy said:

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

Yep, of() is just a shortcut for the full setOutputFormatting() method.

  • Like 2

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
×
×
  • Create New...