dongxi1879 2018-03-22 17:25
浏览 23
已采纳

Drupal检索名字而不是名字/真实姓名?

How can I retrieve the first name instead of name (raw username) or realname, so I can use it in an email template variable !username?

$variables['!username'] = $params['account']->realname;

http://cgit.drupalcode.org/faq_ask/tree/faq_ask.module?id=be753ca5c5fe51f33c0515999ceb3a4179298da8#n1052

Not sure if that relates to realname or perhaps where 'account' is defined to something...?

I created a field for first name that gets pulled by LDAP to provide for realname and have the token [user:field-first-name].

Can I pull this from the token somehow?

Update - code where user load is used:

$account = user_load($expert->uid);
        $params = array(
          'category' => is_object($term)?$term->tid:-1,
          'question' => $node->title,
          'question_details' => $node->detailed_question,
          'nid' => $node->nid,
          'creator' => theme('username', array('account' => user_load($node->uid), 'plain' => TRUE)),
          'account' => $account,
        );

I tried

$account = user_load($expert->uid);
$first_name = $account->field_first_name['und'][0]['value'];
        $params = array(
          'category' => is_object($term)?$term->tid:-1,
          'question' => $node->title,
          'question_details' => $node->detailed_question,
          'nid' => $node->nid,
          'creator' => theme('username', array('account' => user_load($node->uid), 'plain' => TRUE)),
          'account' => $first_name,
  • 写回答

1条回答 默认 最新

  • duanbushi1479 2018-03-23 09:29
    关注

    If you created a custom field for the first name and want to access it using the user email, you can do it like this:

    $user = user_load_by_mail($mail); 
    $first_name = $user->field_first_name['und'][0]['value'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)