Forums / General / Fetching Object Relation Node Name / Comment58467
John Smith
Thursday 15 April 2010 9:24:35 am
If you know how to get the info using the template engine, you can easily get it using PHP, using the attribute() method.
First, a small correction: your attribute will contain a link to an object, not a link to a node. That's why it's called object relation, and not node relation ;)
Now, for the actual question, the first pieces of your code are alright. Once you know what the content() method of an ezcontentobjectattribute of type 'object relation' returns, you're almost done. According to http://ez.no/doc/ez_publish/technical_manual/4_x/reference/datatypes/object_relation, in the "Raw output" chapter, .content on such an attribute returns the eZContentObject. All you need is the node for this object. The easiest way is to request the main node. Once you have it, you can easily get its name:
$userLink = $userMap['userLink']->content(); $node = $userLink->attribute( 'main_node' ); $nodeName = $node->attribute( 'name' );
Like in templates we use to print all the keys/ values with {$node|attribute(show)}. In php, I am using print_r. On your code I tried printing the value by
print_r ($userLink) but could find any key like "main_node".