Hide Root Menu

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

Hide Root Menu

Post by zunair »

How can we hide the Root Menu and draw again according to userlevel.

Please reply.


Webmaster
User
Posts: 9430

Post by Webmaster »

Use Menu_Rendering server event, see Server Events and Client Scripts in the help file.


zunair
User
Posts: 125

Post by zunair »

the following is ok, but this is adding manual menu items. How can we see which menu items allotted to the CurrentUserID
and display them through loop.

function Menu_Rendering(&$Menu) {
if ($Menu->IsRoot) { // Root menu
$Menu->Clear();
$Menu->AddMenuItem(1, "MyName1", "MyMenuText1", "MyPage1.php");
$Menu->AddMenuItem(2, "MyName2", "MyMenuText2", "MyPage2.php");
}
}


mobhar
User
Posts: 11761

Post by mobhar »

Please see the code of "AddMenuItem" method in "class cMenu" from the generated "ewshared11.php" (assume you are using v11).

As you can see, there are 9 parameter in that method. You may play with $allowed (the 7th parameter) so that the menu, for example, will not be allowed to guest user:

$Menu->AddMenuItem(1, "MyName1", "MyMenuText1", "MyPage1.php", -1, "", IsLoggedIn(), FALSE, FALSE);

If you want to allow that menu item only for the user who has CurrentUserID = 1, then try this (no need loop for this):

if (CurrentUserID() == "1") { // logged in user
$Menu->AddMenuItem(1, "MyName1", "MyMenuText1", "MyPage1.php", -1, "", TRUE, FALSE, FALSE);
}


zunair
User
Posts: 125

Post by zunair »

I thought, i was unable to explain my requirement. Let me explain in simple words.

I want to remove root menu and display it again by checking the Current User ID (for difference purposes).

Please help me to resolve my issue.


mobhar
User
Posts: 11761

Post by mobhar »

For example:

function Menu_Rendering(&$Menu) {
if ($Menu->IsRoot) { // Root menu
$Menu->Clear();
if (CurrentUserID() == 1) {
$Menu->AddMenuItem(1, "MyName1", "MyMenuText1", "MyPage1.php");
} else {
$Menu->AddMenuItem(2, "MyName2", "MyMenuText2", "MyPage2.php");
}
}
}


Post Reply