sebastiaan Posted July 26, 2018 Posted July 26, 2018 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)
kongondo Posted July 26, 2018 Posted July 26, 2018 $roles->find('');// all roles //$roles->find($selector);// if want particular roles http://processwire.com/api/ref/roles/ Adapt as required for module use 4
netcarver Posted July 26, 2018 Posted July 26, 2018 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. 2
sebastiaan Posted July 26, 2018 Author Posted July 26, 2018 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
adrian Posted July 26, 2018 Posted July 26, 2018 To expand on @netcarver's suggestion with Tracy and the find selector suggested by @kongondo In the Tracy Console panel you can do this. This finds all roles and then builds an array of the names for each of them. PS - you can also do: find('*') if it seems more semantic to you.
adrian Posted July 26, 2018 Posted July 26, 2018 I should also add that you can also do: 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: 3
sebastiaan Posted July 27, 2018 Author Posted July 27, 2018 thanks for all your reply's and helpfull tips
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