Fetch a class attribute by is ID only, in PHP

Author Message

Olivier Portier

Thursday 12 March 2009 3:45:27 am

Hi eZ Forum,

In PHP code, i fetched an object that have reverse related objects.
I got the reverse related list like this :

// Fetch object ID 1231
$object = eZContentObject::fetch( 1231 );

// Get all reverse relations grouped by attribute
$all_reverse_related_object_list = $object->reverseRelatedObjectList( false, 0, true, array( 'AllRelations' => true ) );

Now i got this in $all_reverse_related_object_list :

array(1) {
  [391]=>
  array(8) {
    [0]=>
    object(eZContentObject)#48 (22) {
      ["ID"]=>
      string(4) "1252"
      ["Name"]=>
      string(28) "My reverse related object title 1"
....
    [8]=>
    object(eZContentObject)#48 (22) {
      ["ID"]=>
      string(4) "1260"
      ["Name"]=>
      string(28) "My reverse related object title 8"
... }
}

My attribute ID is <b>391</b> and i would like to fetch this attribute, and check his identifier (media is the identifier). Without knowing from which content class is part of, neither his version, just fetching it by his ID.

I tried this :

$reverse_attribute = eZContentObjectAttribute::fetch( 391 );

or this

$reverse_attribute = eZContentObjectAttribute::fetchByClassAttributeID( 391 );

without any success.

Does any one could help me on this ?
Thanks
Olivier

Olivier Portier

Thursday 12 March 2009 8:33:02 am

The attribute ID is a ContentClassAttribute not a ContentObjectAttribute.
So to get the identifier of this attribute, i just have to do this :

        $reverse_attribute = eZContentClassAttribute::fetch( $attribute_id );
        $attribute_identifier = $reverse_attribute->attribute('identifier');

I reached my goal !!!
Olivier

André R.

Thursday 12 March 2009 9:54:47 am

In 4.1 you can also use eZContentClassAttribute::classAttributeIdentifierByID / classAttributeIDByIdentifier, this is cached so no db calls are done.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Olivier Portier

Friday 13 March 2009 1:39:49 am

Great, it is much better like this :

    $reverse_attribute = eZContentClassAttribute::classAttributeIdentifierByID( 391 );

Thanks André

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