Share » Forums » Developer » Get ClassName after...

Get ClassName after eZContentObject::fetchByNodeId()

Get ClassName after eZContentObject::fetchByNodeId()

Tuesday 22 December 2009 2:12:13 am - 7 replies

Modified on Wednesday 24 March 2010 1:15:06 am by Damien MARTIN

Author Message

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

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu