Forums / Developer / Get ClassName after eZContentObject::fetchByNodeId()

Get ClassName after eZContentObject::fetchByNodeId()

Author Message

Damien MARTIN

Tuesday 22 December 2009 2:12:13 am

Hi there,

I have a problem with eZContentObject::fetchByNodeId().

When I try to fetch a node like the 64, I use something like that (in fact it's in a loop) :

$noeud = eZContentObject::fetchByNodeId(64);

But when I want to see what it returns with :

ezDebug::writeNotice(print_r($noeud, true), "Damien");

The output shows something like :

 eZContentObject Object

(
    [ID] => 62
    [Name] => My wonderfull folder
    [CurrentLanguage] => fre-FR
    [ClassName] => 
    [ClassIdentifier] => 
    [DataMap] => Array
        (
            [3] => Array
                (
                    [fre-FR] => Array
                        (
                            [nom] => eZContentObjectAttribute Object
                                (
                                    [HTTPValue] => 
                                    [Content] => 
                                    [DisplayInfo] => 
                                    [IsValid] => 

So, why haven't I the correct node ID in the returned Object while the datas are good (DataMap, has the correct values) ?

This problem is embarassing because I need to know the ClassName whos is not defined in the returned object...

For information :
eZ Publish version 4.2.0
Installed as an ezwebin template (without content)

Thanks

Bertrand Dunogier

Tuesday 22 December 2009 3:07:38 am

First, you don't need to pass your variable through print_r, eZDebug::write* do it automatically.

Then... nothing's wrong with the returned values. You're confusing object & node ID. You're fetching the eZContentObject that matches node 64, and it happens that this object's ID is 62. Since multiple nodes can link to the same object, it is expected that they are different.

if your object only has one node, you can check that the value is correct by using:

$noeud->attribute('main_node_id');

Note that $noeud is wrong here, as the object is an object, not a node ;)

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

Damien MARTIN

Tuesday 22 December 2009 5:27:22 am

Thanks Bertrand,

Now, I understand why I haven't the same value in ID...

But I still don't understand why the ClassName attribute is empty.
Have I to do something more to get it ?

And as you said, I will correct my source code and change $noeud for something different :)

Jérôme Vieilledent

Tuesday 22 December 2009 5:46:05 am

Hi Damien
Actually, this property is not static. It means that it is filled by calling a method (attribute() in that case, which is automatically called in templates).
So, to have your class name, you should do this :

$object = eZContentObject::fetchByNodeId(64);
$className = $object->attribute('class_name');

You can find all the attributes (or properties) available with this method in the objects reference documentation. Also note that, when you find a PHP class extending eZPersistentObject in eZ Publish, just have a look in the definition() static method. You'll find here all attributes you want ;)

A little more documentation about eZPersistentObject.

Damien MARTIN

Tuesday 22 December 2009 5:54:58 am

Thanks Jérôme !

It works well !

I'll read the documentation about eZPersistentObject and the object reference documentation (I bookmarked them).

I'm sorry but I'm a beginner in writting extensions for eZ... But it's really exciting !

I will mark the topic as solved and I will change it's name for something more realistic than the current.

Thank you again Bertrand and Jérôme.

Jérôme Vieilledent

Tuesday 22 December 2009 6:00:23 am

I'm happy I could help you :)

Don't be sorry, we were all beginners once !
Anyway, I'm happy you enjoy developping eZ extensions ! You then may want to share them on the projects website ;).

Damien MARTIN

Tuesday 22 December 2009 6:19:25 am

I started to post some things : eZ Online Template Editor

But there is no "eZ code" inside, it is just template overrides.

I make extensions for my job and I hope to release them in a near futur !

Bertrand Dunogier

Tuesday 22 December 2009 2:00:47 pm

A possibly useful tip: when you look at objects reference pages on the documentation, there is a "Static" column. This indicates wether the value for this attribute is fetched by default (usually a value stored in the SQL table as is), or has to be fetched / computed when requested.

http://ez.no/doc/ez_publish/technical_manual/4_x/reference/objects/ezcontentobject

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

eZ debug

Timing: Jan 29 2025 13:36:44
Script start
Timing: Jan 29 2025 13:36:44
Module start 'content'
Timing: Jan 29 2025 13:36:44
Module end 'content'
Timing: Jan 29 2025 13:36:44
Script end

Main resources:

Total runtime0.1467 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0051 588.0781180.8125
Module start 'content' 0.00510.0072 768.8906106.6484
Module end 'content' 0.01230.1343 875.5391535.8750
Script end 0.1466  1,411.4141 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00332.2759200.0002
Check MTime0.00130.9134200.0001
Mysql Total
Database connection0.00070.475210.0007
Mysqli_queries0.097166.18281410.0007
Looping result0.00120.82481390.0000
Template Total0.133991.310.1339
Template load0.00080.554310.0008
Template processing0.133190.729010.1331
Override
Cache load0.00060.400910.0006
Sytem overhead
Fetch class attribute can translate value0.00110.717210.0011
XML
Image XML parsing0.00030.182910.0003
General
dbfile0.00885.9853200.0004
String conversion0.00000.003430.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs