Hiding menu items from userlevels

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
cdmak
User
Posts: 27

Hiding menu items from userlevels

Post by cdmak »

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


kirondedshem
User
Posts: 642

Post by kirondedshem »

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;

}


cdmak
User
Posts: 27

Post by cdmak »

Thank you again for your kind help, I understand this now, makes sense.


cdmak
User
Posts: 27

Post by cdmak »

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
User
Posts: 27

Post by cdmak »

Is it possible to put more users in this? I tried and it does not work. Thank You

// 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
}
}

if ($Item->url == "customers.php" )
{
//get the user level of logged in user
if(CurrentUserLevel() == 2)
{
return FALSE;//dont draw it
}
else
{
return TRUE;//draw it
}
}

return TRUE;
}


cdmak
User
Posts: 27

Post by cdmak »

Got it thanks, works now.

Thank You


Post Reply