开发者

Drupal html user id

I'm using Drupal 6.16: I think 开发者_Go百科I have a pretty simple question. How can I get the current user id and put it in a menu tab. What I would like to happen is when the user logs in and wants to change their name, email etc to click a menu tab. I image it would look something like this: http://domain.com/user/{userid}/edit

Thanks in advance! msindle


That's more difficult than you would think, because menu items are cached. There is not a straightforward way to create dynamic menu items with the userID in it.

What you can do, is write a custom module and imitate the behavior of the 'user' path. With an implementation of hook_menu you create a menu item, with the path 'user/edit' (just like user_menu() creates $items['user']). Next you create a menu callback user_edit_page(), similar to user_page(), which gets the id of the current user and returns the user edit page:

function user_edit_page() {
  global $user;
  if ($user->uid) {
    menu_set_active_item('user/'. $user->uid .'/edit');
    return menu_execute_active_handler();
  }
  else {
    return drupal_get_form('user_login');
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜