0

I am using D7 and views for one of my projects. I have created a view that displays the name, age, role and orders of the user. I would like these things to displayed only for the logged in user. For instance user/1 should get his name,age,role and orders only, he should not be able to see the other's details. Similarly each and every user must be able to see their own details. I know i can use the uid from the url, but not sure how to achieve this.

Thanks

-1

You want the global variable $user...

http://api.drupal.org/api/drupal/developer!globals.php/global/user/7

Then the user_load() function...

http://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_load/7

  • Is there any way that i can use this in the views instead of coding? – user4081 Jul 2 '12 at 12:41
  • You can add a relationship of the current logged in user to your view. This should help: stackoverflow.com/a/10440513/1266251 – Alex Gill Jul 2 '12 at 12:47
1

Create a custom module and add following function.

function login_user_fn(){
   global $user;
   //print_r($user);
   $fid = $user->picture;
   $file = file_load($fid);
    if($file !=''){

    $user_pic  = theme('user_picture', array('account' => $user , 'path' => $file->uri,));

    return ('Hello '.$user->name.'<br/>'.$user_pic);
  }
}

And than call custom function " login_user_fn()" in our drupal custom block body.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy