Hiding menu items from userlevels

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.

Hiding menu items from userlevels

Postby cdmak » Thu Jan 11, 2018 7:12 pm

Hello,

I'm trying to hide a 3 menu items from the Administrator group level "-1" I looked at "MenuItem_Adding" in the help but it seems pretty vague, I don't want to clear the entire menu and then add back the menu items for admin, just want to hide a few.

Is there a way to do this simply?
Thank You
cdmak
 
Posts: 22
Joined: Tue Nov 22, 2016 10:51 am

Re: Hiding menu items from userlevels

Postby kirondedshem » Thu Jan 11, 2018 7:30 pm

Read the help menu about the server events of the menu, coz MenuItem_Adding is called before rendering any menus item on themenu, And a menu item wont be drawn if you return false from this event even if it was supposed to be drawn. For example am hiding the home, news and cars menu items from the admin user in demo project.

// MenuItem Adding event
function MenuItem_Adding(&$Item) {

//var_dump($Item);
// Return FALSE if menu item not allowed

//the menu item is one of the following
if ($Item->url == "home.php" || $Item->url == "news.php" || $Item->url == "carslist.php")
{
//get the user level of logged in user
if(CurrentUserLevel() == -1)
{
return FALSE;//dont draw it
}
else
{
return TRUE;//draw it
}
}


return TRUE;
}
kirondedshem
 
Posts: 310
Joined: Sat Jan 28, 2017 7:13 pm

Re: Hiding menu items from userlevels

Postby cdmak » Fri Jan 12, 2018 3:24 pm

Thank you again for your kind help, I understand this now, makes sense.
cdmak
 
Posts: 22
Joined: Tue Nov 22, 2016 10:51 am

Re: Hiding menu items from userlevels Special Note

Postby cdmak » Mon Jan 15, 2018 4:49 pm

Special Note:

If the menu is not hidden click on the link and see what is displayed in the browser and copy and paste into the string, take a look at the carslist.php example below. Now the cars list will be hidden.

if ($Item->url == "home.php" || $Item->url == "news.php" || $Item->url == "carslist.php?cmd=resetall")

Thank You
cdmak
 
Posts: 22
Joined: Tue Nov 22, 2016 10:51 am


Return to General Discussion (PHPMaker)