Jump to content

get all roles


sebastiaan
 Share

Recommended Posts

How do you get all roles in a module? (i want to create a migration to set the permissions of templates and fields)

i tried :

            $rolles = wire('roles');
            var_dump($rolles);
            var_dump($roles);
            var_dump($this->roles);

but all 3 return 0 while i have 3 different roles(guest, superuser, test)

Link to comment
Share on other sites

1 hour ago, kongondo said:

 


$roles->find('');// all roles
//$roles->find($selector);// if want particular roles

http://processwire.com/api/ref/roles/

Adapt as required for module use

 

yeah i saw that page but didnt realise it could have been a empty selector, thanks

 

1 hour ago, netcarver said:

Hi @sebastiaan and welcome to the forum.

You could try this...


$role_list = wire('pages')->find('template=role');

I also highly recommend installing the Selector Test module or the Tracy Debugger Module so you can explore using PW's selectors for this sort of thing.

thanks this worked for what i wanted, and will install one of those

Link to comment
Share on other sites

I should also add that you can also do:

image.png.b56b97a42ad0f7935a913c72d176023b.png

so $roles does contain all the roles, it just doesn't return an array that can be dumped by default, which is different to $templates and $fields - this seems like a bit of an API inconsistency to me.

Also to note, you can do:

image.png.5b7fb19d579a67b3aa2329606b7c6174.png

 

 

  • Like 3
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...