bwakad Posted May 6, 2014 Share Posted May 6, 2014 I have added a role named TESTER, and a user named TEST. My login(.php) template and page is ready but I want this only visible in menu if viewer is guest. The login - page role says: guest (everyone) - view (and of course superuser) but no tester! The login - template says : guest, tester, and superuser. The checkbox for tester cannot be unchecked...? The access > roles > tester : is (for now) set to view and update password. The access > users > test : is set to guest and tester. I cannot uncheck the guest (is required warning)...? I guess the guest is required by all roles one creates. My question is, do I have to do something in the backend to (based on roles) hide a page from the menu, or is there something wrong with my setup, or is there another way to do this? I hope someone can tell me what to do... Link to comment Share on other sites More sharing options...
Martijn Geerts Posted May 6, 2014 Share Posted May 6, 2014 if (count($user->roles) === 1) { echo "I'm guest & guest only."; } 1 Link to comment Share on other sites More sharing options...
bwakad Posted May 6, 2014 Author Share Posted May 6, 2014 hey, thanks man! Link to comment Share on other sites More sharing options...
Soma Posted May 7, 2014 Share Posted May 7, 2014 Or use the $user->isGuest() 1 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted May 7, 2014 Share Posted May 7, 2014 if ($user->id === $config->guestUserPageID) { echo "i'm a guest"; } Link to comment Share on other sites More sharing options...
Pete Posted May 7, 2014 Share Posted May 7, 2014 Yet another way to check for guests only is with $user->isLoggedIn() 1 Link to comment Share on other sites More sharing options...
Soma Posted May 7, 2014 Share Posted May 7, 2014 Or if($user->name == "guest") ... 1 Link to comment Share on other sites More sharing options...
bwakad Posted May 7, 2014 Author Share Posted May 7, 2014 I did it by isLoggedIn(), which is much easier to read. So in my foreach loop I use this code: foreach($children as $child) { $class = $child === $page->rootParent ? " class='active'" : ''; if ($user->isLoggedIn()) { // is member? if ($child->name == "login") { // skip login page if logged in continue ; } } else { // is guest ! if ($child->name == "profile" OR $child->name == "logout") { // skip profile OR logout page if logged out continue; } } echo "<li $class><a href='{$child->url}'>{$child->title}</a></li>"; } Then I would think I also have to give some kind of statement in top of page, something like direct acces not allowed if one would enter it in the browser url? Link to comment Share on other sites More sharing options...
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