I'm not sure where the value code section is getting its data from but it's not at all representative of the data from each row. Can anyone suggest how the $data and $row variables are populated? For a NID field in my view row which is set to 20, exporting the $row->nid value to the $static variable and then outputting this field in the output code section shows a value of 353 for every single row. Something is obviously amiss.

Comments

Sawascwoolf’s picture

I'm facing the same problem.
I could imagine this has something to do with using a relationship in this particular view.

Can you confirm this?

joegl’s picture

Having the same issue. In the "Value Code" section I:

return $data;

and then in the "Output Code" section I:

print_r($value);

I trace down the field data I want and return a value from the $data object in the "Value Code" section:

return $data->field_field_birthday_month[0]['raw']['value'];

And then in the "Output Code" section I:

print $value;

The $value is always blank and nothing is outputted. No matter what value I pick from the $data object in the "Value Code" section it's always blank.

Accessing the $data object in the "Output Code" section works fine. However, I need it set in the "Value Code" section so I can use it in a Global: PHP Sort Criteria.

I am also aware of the issue with $row object values containing the NID instead of the actual data, but usually I'm able to bypass it with the $data object. Apparently this only works in the "Output Code" and not "Value Code". Does anyone know a workaround?

joegl’s picture

I used a workaround for now but I don't like it. I am pulling users so I use the $data->uid and user_load functions to get the user's correct data in the "Value Code" section. E.g.,

$user = user_load($data->uid);
return $user;

From there you can trace the data in the "Output Code" section by doing a:

print_r($value);

Once you've traced your field you can then set it like so in the "Value Code" section:

$user = user_load($data->uid);
return $user->field_birthday_month['und'][0]['value'];

I am not sure if this is adding extra queries to the database or if it's all aggregated by views (I assume it's not aggregated because it's raw PHP but I don't know the inner workings of this module). I don't like the idea of extra database hits but it's the best I could do.

This works for the PHP sort now because the value is being set in the "Value Code" section.

For those of you working on nodes, you would instead use:

$node = node_load($data->nid);
return $node;

Cheers! This is a great module.

fizk’s picture

Status: Active » Closed (works as designed)

$static persists across rows, so doing something like $static = $row->nid in the Value code section will be overwritten by each row, leaving you with $static having the value of the last row. Thus, printing $static in the Output code section shows the same value for every row.

joegl’s picture

Could you be more descriptive? I am not sure how your comment addresses this exact issue?