Jump to content

Recommended Posts

Posted

Hello everyone!

My first post here. I found Processwire a while ago and have recently been getting to know the system. So far i like it a lot.

Right now i'm trying to make a "page"-field where an admin can select and attach users with a specific role. I can get a list of all users, and filter by different fields, but i don't know how to access the roles. As i understand it, selectors can not be used to find user roles, so i wonder if anyone has another approach. I could add a new field to each user with the role names, but that seems a bit awkward.

Thanks in advance!

Posted

Ah, thanks a lot for the quick answer!

I tried "role=something" but not "roles" and then i got lost in the documentation...

Now back to work :)

  • Like 1
Posted
So far i like it a lot.

Well said, because soon you won't like it a lot anymore. You will love it ;)

  • Like 6
  • 1 year later...
Posted

Just a quick note for future drive-by readers.  For some reason

$users = wire('pages')->find("template=user,roles=buyer,sort=email");

didn't work for me, but

$users = wire('users')->find("template=user,roles=buyer,sort=email");

did.  Not sure why.

  • Like 1
Posted

Just a quick note for future drive-by readers.  For some reason

$users = wire('pages')->find("template=user,roles=buyer,sort=email");

didn't work for me, but

$users = wire('users')->find("template=user,roles=buyer,sort=email");

did.  Not sure why.

Both work here - what version of PW are you running?

One thing to note though is that you shouldn't be overwriting $users as this contains all users in the system. If you redefine it, you won't have access to all users via $users further down in your code.

  • Like 1
  • 4 months later...
Posted

i can verify that the "users" template doesn't work the same way as regular templates:

  • i have a "student" role
  • when i put "roles=student" as the custom selector, the field seems to work perfectly: it shows all users with the "student" role, and shows nobody else
  • however, when i'm trying to save the page, i get this message: Error saving field "student" - Page 1017 is not valid for student

if i use custom php (when of course i can't use autocomplete) it works perfectly with all of these:

  • return wire("users")->find("roles=student");
  • return wire("pages")->find("roles=student");
  • return $pages->find("roles=student"); // which, incidentally, is the same that the custom selector is supposed to resolve

in short, it must be something about the custom selector validation code; if i find some time i'll look some more into it

  • Like 1
  • 9 months later...
Posted

Hi I was wondering if there's a workaround for this?

I created a new field called blog_author which is a page field. 
It has a selector of "'template=user, roles=editor".

When I try and save down a blog post that has the new blog_author field in it, it's returning the following error.

Error saving field "blog_author" - Page 1415 is not valid for blog_author (Page 1415 does not match findPagesSelector: template=user, roles=blog-author)

I can see the blog authors and select one without errors.

The error occurs when I'm saving.

Have tried to make the template type a basic page field type (instead of user) , but it returns the same error.

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