Hello,
I have a view set up that uses a number of relationships to grab content from the correct DB tables. Views PHP does not appear to support relationships, so the only variables I see in the list of those available are those that do not require a relationship. How can I achieve this functionality?

Comments

sadashiv’s picture

Views Php show fields added to the display of views as available variables. If you want some variable which you got because of the relationship then add the field to the fields to display. If you don't want the field to be displayed to the end user but just want it for computation then check the "Exclude from display" check-box.

Hth,
Sadashiv.

johnv’s picture

Those data are available. See this code (from a join of 3 entities) to see where it is stored:

  $node1  = & $data->_field_data['nid']['entity'];
  $node2 = & $data->_field_data['node_field_data_field_site_ref_nid']['entity'];
  $node3  = & $data->_field_data['field_fixture_ref_node_nid']['entity'];
LTech’s picture

$node = &$row->nid; will show the nid if I'm not using a relationship.
so for nid using a relationship I've tried:
$node = &$row->nid;
or $node = &$data->nid;
and nothing shows.
I don't understand comment #2.
How do I show the nid that is using a relationship?
Thanks

smurfxx’s picture

Issue summary: View changes

I have the same problem:
in my view I added a related field "age" and next to it a php field.

For testing that, the output of field "age" is correct.

When I build the php field output the available variable is "$row->field_age", the output is "1".

Every field that come from a related table is "1" but if I use them in the default views usage they display the right value.

As proof of that, doing a print_r($row) I see that every related filed has value "1".

Is possible to print the real value of the related field without a specific query?

Liam Morland’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev