Posted by mayur.pimple on June 30, 2012 at 5:27am
Hi
I have use hook_menu_alter()
I want to access uid of current view user in menu alter function.
Thanks Mayur
Hi
I have use hook_menu_alter()
I want to access uid of current view user in menu alter function.
Thanks Mayur
Comments
Simple
hey you can get the viewing user id :
$user_id = arg(1);
blank value
_menu_alter(&$items) {
$user_id = arg(1);
dsm($user_id);
}
value is not print. but when i use this arg(1) in hook_user() then print the value.
Try this
global $user;
$user_id=$user->uid; //to get the user id
$user_name=$user->name; //to get the user name
this is current user info
i don't want current login user info. i want current view of user page info
Don't use global $user
You shouldn't use
global $user
because it could expose you to a privilege escalations if you make an error while handling the global user object. A safe alternative is user_uid_optional_load() which will return the current logged-in user if called without an argument.$user = user_uid_optional_load();
$user_id=$user->uid; //to get the user id
$user_name=$user->name; //to get the user name
getting userid from URL
This worked for me
page URL: http://www.example.com/user/
In .module page
$userpageload = user_load(arg(1));
$useridofcurrentuserview = $userpageload->uid;
Neeraj
Valuebound, Drupal development
Subscribing
+1
I were also facing the same issue.
Issue:
I want to get the user id of authenticate user while sub admin is viewing authenticate user profile.
We have a profile item in menu whose path is set as 'user'. So the url is https:www/sitename.com/user instead of http://www.sitename.com/user/[uid].
Solution:
I used menu tokens module and change my menu item path 'user' to 'user/[current-user:uid]'.
It may help anyone.
Thanks
menu_get_object
I'm using menu_get_object('user') and get user object of view user profile page