1
global $user;  
$user->uid ;
print_r($user->uid);
print "print out the user value" . $user->uid;

$uid =3;

$account = user_load($user->uid); 

$profile = profile2_load_by_user($account);

$print_first_name =  drupal_render(field_view_field('profile2',$profile['main_profile'], 'field_first_name'));
print $print_first_name;

What I have attempted to do is to pass the $user->uid to the user_load function. When I pass $uid = 3 to the user_load function it seems to work fine. I am wondering what approach I should try to fix this problem.

error message:

EntityMalformedException: Missing bundle property on entity of type profile2. in entity_extract_ids() (line 7562 of /home/td6/public_html//includes/common.inc).

1
  • This is poorly titled as it seems to be cut off and the error message in the title is different to the one you mention at the end of your post.
    – rooby
    Commented Feb 2, 2013 at 5:18

1 Answer 1

1

Your mistakes is here main_profile , profile type always start with profile_name . just need change main_profile to profile_main

global $user;  
$user->uid ;
print_r($user->uid);
print "print out the user value" . $user->uid;

$uid =3;

$account = user_load($user->uid); 
$profile = profile2_load_by_user($account);


$print_first_name =  drupal_render(field_view_field('profile2',$profile['profile_main'], 'field_first_name'));
print $print_first_name;

If you want see all your profile type and correct name and it's contents print_r or var_dump $profile

$profile = profile2_load_by_user($account);
print_r($profile);
1
  • profile2 profiles do not always start with profile_, but like you say, the issue is that main_profile is not the name of the profile. Also, drupal_render takes an element by reference so you really should pass in a variable, not a function. For example, set a variable to the result of field_view_field and then pass the variable into drupal_render().
    – rooby
    Commented Feb 2, 2013 at 5:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.