Download & Extend

Get username instead of uid

Project:Voting API
Version:6.x-2.0-rc2
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (duplicate)

Issue Summary

Hi,

I made a voting api relationship in views.

I can now add a field to show which user has voted. Views shows me the uid of that user. Is it possible to show the username as well? I'd like to have the username instead of the uid.

Thanx in advance!!!

Comments

#1

Managed to get it to work with a views tpl file, views-view-field--viewname--uid.tpl.php

and the following code:

  $user = user_load($row->{$field->field_alias});
  $userpath = 'user/' . $user->uid;
  print l($user->name, $userpath);

I could have used a custom theme function as well but I'd like to have the default theme function.

#2

I'm looking for a solution too! But I don't understand yours. Can you be a little more specific?

#3

subscribing

#4

See http://thedrupalblog.com/category/tags/views-view-fieldtplphp for more about the workaround provided by timlie.

I would think there should be an appropriate views relationship between the users table and the votingapi tables so that it would be easier to accomplish this.

#5

Piece of cake now. Thanks.

#6

Status:active» closed (duplicate)

#327903: Add "Individual voter" relationship - fixed in the official 2.0 release. Thanks!

#7

Be very careful, timlie. Your code has a security bug. When you override $user variable, you could be giving access to your backend to anonymous visitors.

It's always better to use another name, such as $testUser or something similar.