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

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

eZ debug

Timing: Jan 30 2025 00:19:19
Script start
Timing: Jan 30 2025 00:19:19
Module start 'layout'
Timing: Jan 30 2025 00:19:19
Module start 'content'
Timing: Jan 30 2025 00:19:19
Module end 'content'
Timing: Jan 30 2025 00:19:19
Script end

Main resources:

Total runtime0.0136 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0041 588.2656151.2266
Module start 'layout' 0.00410.0022 739.492236.6953
Module start 'content' 0.00640.0060 776.1875102.9063
Module end 'content' 0.01230.0012 879.093841.9922
Script end 0.0135  921.0859 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002215.8309140.0002
Check MTime0.00107.4412140.0001
Mysql Total
Database connection0.00064.397410.0006
Mysqli_queries0.002216.144830.0007
Looping result0.00000.080710.0000
Template Total0.00096.410.0009
Template load0.00074.926910.0007
Template processing0.00021.441210.0002
Override
Cache load0.00053.413810.0005
General
dbfile0.001712.499680.0002
String conversion0.00000.050840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_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