Jump to content

Recommended Posts

Posted

I have this code, and 2 things do not work: sort by roles, and display the role of each user.

I did read in the API I can use $type = $child->get("roles"); echo $type; but that seems a bit over the top, or not?

Furthermore, as I understand, any extra role added will also be using the guest role. Why is that???

if($user->hasRole("member"))  $selects = $users->find("roles=company");
if($user->hasRole("company")) $selects = $users->find("roles=member");
if($user->hasRole("superuser")) $selects = $users->find("roles=member|company, sort=-roles");

foreach($selects as $child) { ?>

    <row>
        <div class="medium-6 columns"><?php echo $child->name; ?></div>
        <div class="medium-6 columns"><?php // display role ?></div>
    </row>

<?php } ?>

Posted

So in the first foreach I need to cycle through the second one?

edit -

Maybe it's easier to just use $selects = pages->find("template=user"); in this case it's the superuser, which has right to see all...

And I believe on the user template I can acces the field roles, am I right?

edit - this did not work either

Btw, does anyone know why the role guest is present in all other roles.?

Posted

I'm not sure what you are trying to acomplish. Anyway the folowing code prints all the roles and name of the role for the current user

foreach($user->roles as $role) {
    echo "Role: {$role} = {$role->name} <br>";
}

Or if you need the role for a specific user

$u = $users->get('admin');
foreach($u->roles as $role) {
    echo "Role: {$role} = {$role->name} <br>";
}

All anonymous visitors, loggedin users, admins etc... by default have the guest role

  • Like 1

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...