Jump to content

rename users


PeterDK
 Share

Recommended Posts

Hi!

Quick question. Hopefully...

Is it possible to rename users to 'riders' and move those pages from behind the 'admin'?

The url of 'users' would then be /riders/ridername (instead of /admin/users/ridername)

This without breaking 'permissions' and 'groups'.

Thanks!

Link to comment
Share on other sites

Someone more knowledgeable than I will give you a better answer but am wondering..why not just create pages outside admin for each user if that's what you are after? Behind the scenes, users (i.e. those under admin/users) are also pages! So, you can create a parent page "riders" with child pages "ridername". You will just have to access them with the $page or $pages variables rather than $user. You can then associate users (created in Admin) with their pages (those under "riders").

A search of the forums will reveal this has been done before (and it gives you more options quickly, although users under Admin can also be extended [via the user template]).

You might also want to check out the various PW modules that help manager user access on a page or field level.

Edited for clarity

Edited by kongondo
  • Like 1
Link to comment
Share on other sites

You can make up your own users system, and sometimes it's the simplest route to achieve something. But I would try to get it done with regular PW users first. You can always map fictional page names to usernames via URL segments. For instance, if you had a template called 'riders' and you enabled 'URL segments' in the 'URLs' tab of your template, then your /site/templates/riders.php file could have code like this:

if($input->urlSegment1) {

  $rider = $users->get("name=$input->urlSegment1"); 
  if(!$rider->id || !$rider->hasRole("rider")) throw new Wire404Exception("Unknown rider");   

  // display rider
  echo "<h1>$rider->name</h1>";
  echo $rider->body; // ...or whatever fields you wanted to output

} else {

  // display list of riders
  foreach($users as $rider) {
    if(!$rider->hasRole("rider")) continue; 
    echo "<li><a href='./$rider->name/'>$rider->name</a></li>";
  }
}
  • Like 5
Link to comment
Share on other sites

Ryan,

If Peter went with that approach, what would you recommend he implement in his search.php script to make it possible to find those fictional rider pages?

Maybe something like this:

$matches = $pages->find("title|body|sidebar~=$q, limit=50");
$rider_matches = $users->find("name~=$q, limit=50");

$matches->append($rider_matches);

foreach($matches as $m) {
    if($m->template == 'riders'){
       $out .= "<li><p><a href='/riders/$m->name/'>{$m->name}</a></p></li>";
    }
    else{
        $out .= "<li><p><a href='{$m->url}'>{$m->title}</a><br />{$m->summary}</p></li>";
    }
}
 
  • Like 2
Link to comment
Share on other sites

If Peter went with that approach, what would you recommend he implement in his search.php script to make it possible to find those fictional rider pages?

Your solution looks good, but would make the riders always appear at the bottom of the results. Maybe that's okay, but I think riders and other types of pages might be different enough that they'd warrant further segmentation or their own search, perhaps their own tabs at the top of the page, or regular pages in left column, riders in right column, etc.

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