$node.data_map.(...) versus $node.object.data_map.(...) ?

Author Message

Craig Hirsch

Thursday 07 April 2005 9:44:07 am

Can someone clarify for me:

1) The conceptual difference between accessing a particular content item's data map via $node.data_map.(...) and accessing it via $node.object.data_map.(...) ?

2) The practical effects of doing things one way or the other...?

Thanks in advance.

--
chirsch{AT}gmail{d.t}com

Paul Forsyth

Thursday 07 April 2005 10:31:33 am

They both call the same php function so both return the same result.

In some circumstances you may not have access to the node and use $object.data_map instead.

paul

Kristian Hole

Friday 08 April 2005 12:11:16 am

1)
The conceptual difference is that the node does not have a data_map. The node "contains" the object, so $node.object.data_map is the correct way. $node.data_map is a shortcut.

2)
Should be no practical difference.

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

Hans Melis

Friday 08 April 2005 12:43:50 am

2) There is a practical difference depending on some conditions.

- You must be using ezpublish 3.5
- TemplateOptimization must be enabled
- The variable $node must not be set by a module, but fetched in a template (in other words, a template loaded by a custom module).

In those conditions, $node.object.data_map doesn't work, but $node.data_map does.

http://ez.no/community/bugs/templateoptimization_causes_problems

Hans
http://blog.hansmelis.be

Kristian Hole

Friday 08 April 2005 12:54:18 am

I was ofcourse just thinking of using $node in the view templates in my little head. Must still early in the morning ;)

Thanks for your comment Hans!

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

Xavier Dutoit

Friday 08 April 2005 12:58:09 am

Good question, rising an interresting point: too many ways of doing the same thing doesn't add any value but obfuscate.

What's the added value of $node.data_map instead of $node.object.data_map ? to save 7 bytes ?

Please choose an officially recommanded way, document it properly and declare obsolete the others.

Orthogonality is the best documentation ;)

http://www.sydesy.com

Craig Hirsch

Friday 08 April 2005 9:31:52 am

I will also add this to the discussion - right now, using $node.object is very dangerous when referencing images, because of the PHP bug noted here (whose cause I still don't really comprehend):

http://www.ez.no/community/bugs/call_to_undefined_function_storedata

Working around this bug prompted my question originally -- after two solid long days of working I have finally eliminated all reference to $node.object.data_map.(image datatype attribute)[original] in my code, replacing it with $node.data_map.(...).

So.. it would seem that for all template development the safest bet by far is to use $node.data_map rather than $node.object.data_map, given the bug and Hans' TemplateOptimization comments.

Does everyone agree?

--
chirsch{AT}gmail{d.t}com

Xavier Dutoit

Friday 08 April 2005 9:48:14 am

I don't know what works best in every specific case, but on a conceptual level, I think that datamap belongs to the object, not to the node.

node.data_map just fuels the confusion between object and node IMO.

Xavier

http://www.sydesy.com

Kristian Hole

Monday 11 April 2005 4:16:28 am

I agree with you Xavier that using $node.object.data_map is conceptually better and clearer (and less confusing).

I think the reason that this was implemented was to reduce the overhead for getting the data_map. (Less calls to functional attributes.)

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.