Friday 16 April 2010 2:10:27 am
Hey John. A small background tip here: on the doc page for objects, like the ezcontentobject one you can use here, there is a 'Static' column. This column indicates wether the 'attribute' (in the persistent object sense) is a static one (e.g. always pre-fetched, as an object property) or a non-static, or dynamic one. main_node is dynamic, which means that calling this attribute, either through ->attribute( 'main_node' ) in PHP, or through object.main_node in a template, will trigger a method call. You can find what method is called by looking at the persistent object definition in the eZContentObject class (kernel/classes/ezcontentobject.php), method "definition":
array(
...
"main_node" => "mainNode",
...
) This means you could use $userLink->mainNode() instead of $userLink->attribute(' main_node' ). That is why print_r won't show you this value, and as Gaetano explains, the attribute template operator will, as it scans every attribute, dynamic and static, and show the values. There is a long history of trying to figure out wether it is best to use attribute + the attribute name, or the matching method... the later is probably better when it comes to performances, but the difference is most likely minimal, while the first allows you to re-use your knowledge of the template engine persistent object API. I like this one better, as it improves readability, but the choice depends on you. Parenthesis closed :-)
Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier
|