display username on menu list

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

display username on menu list

Post by made »

how to display username that logged on into menu list?
etc:
Welcome John, menu1, menu2, menu3, logout

thanks in advanced


Webmaster
User
Posts: 9430

Post by Webmaster »

Customize ewmenu.php and echo CurrentUserName() above the menu.


made

Post by made »

can it be done on custom code?
not manually after the page has been generated


Nicole

Post by Nicole »

try this, it's working for me...

MenuItem_Adding server event:

 if ($Item->Id == -1 ) {
        if (IsSysAdmin() )
            $user="Administrator";
        else
            $user = $Security->CurrentUserInfo("vorname")." ".$Security->CurrentUserInfo("name"); // Note: change to your own field names in the user table
    
        if (IsLoggedIn() ) {       
            $Item->Text = '<img border="0" src="phpimages/door_in.png" width="12" height="12" align="top">&nbsp;<b>Logout</b>&nbsp;('.$user.')';
            $Item->ParentId = 18; // Account // Note: moves the "logout" to another menu-level, change to your own parent menu item ID
        }
}

NOTE: This piece of code moves the "logout" to another menu-level and is adding an icon and the name of the user.


jacson

Post by jacson »

i test it
its not working
and logout word is removed from menu


sal1150

Post by sal1150 »

Customize template.php and add this :

<!-- header (begin) --><!-- *** Note: Only licensed users are allowed to change the logo *** -->

<div class="ewHeaderRow"><img src="phpimages/mylogo.png" alt="" border="0">
&nbsp;&nbsp;&nbsp;
<?php if (IsLoggedIn()) { ?>
<!-- display username -->
<span class="phpmaker"> Welcome: <? echo($_SESSION[EW_SESSION_USER_NAME]);?></span>


erzon

Post by erzon »

Try this in Menu_ItemAdding

after the }

type

if ( IsLoggedIn() )
{
echo "Hi, <b> ".CurrentUserInfo("Name");

}

just change the Name to your user field


jacson

Post by jacson »

thank you erzon
yes it's working fine but hi word repeat many


erzon

Post by erzon »

maybe you can post your code.. this code is working for me without any problem


jacson

Post by jacson »

thank you erzon

in server event

menuitem_adding

function MenuItem_Adding(&$Item) {
if ( IsLoggedIn() )
{
echo "Hi, <b> ".CurrentUserInfo("Name");

}

return TRUE;

}

in web appear
Hi jacson, Hi jacson, Hi jacson, Hi jacson, Hi jacson,Hi jacson, Hi jacson, Hi jacson, Hi jacson,


Nicole

Post by Nicole »

The server event menuitem_adding is called as many times as you have menu-items.

You need a logic wich show your echo only one time. Look at my first post!!!


aburajeh

Post by aburajeh »

jacson wrote:
i test it
its not working
and logout word is removed from menu

Hi Nicole,
thank you advance

You code Not work stop at line 26 > >> if (IsLoggedIn() ) {

You can fixed

Thank you again


erzon

Post by erzon »

put the code in Menu_Rendering and remove the return true statement it should work fine


cahilbey
User
Posts: 38

Post by cahilbey »

Thank you all, this works fine for me:

function Menu_Rendering(&$Menu) {
if (IsLoggedIn()){
echo "Welcome back ".CurrentUserName();
}
}


sobrigas
User
Posts: 15

Post by sobrigas »

You can add "Menu Editor", ex: user.

//function MenuItem_Adding

if (IsLoggedIn() ) {
$user = CurrentUserName();
if($Item->Text == 'user') {
$Item->Text = "Hi, <b>" . $user . "</b>";
}
}


Aburajeh
User
Posts: 37

Post by Aburajeh »

cahilbey wrote:
Thank you all, this works fine for me:

function Menu_Rendering(&$Menu) {
if (IsLoggedIn()){
echo "Welcome back ".CurrentUserName();
}
}

IS WORK THANK YOU


Post Reply