Share » Forums » Developer » [Solved] Modify/Update objects from PHP

[Solved] Modify/Update objects from PHP

[Solved] Modify/Update objects from PHP

Wednesday 20 January 2010 2:14:41 am - 5 replies

Modified on Wednesday 20 January 2010 5:51:54 am by Damien MARTIN

Author Message

Gaetano Giunta

Wednesday 20 January 2010 3:01:04 am

take a look at data import extension - it has very clean code to do that

Principal Consultant International Business
Member of the Community Project Board


Wednesday 20 January 2010 5:51:29 am

Thank you Gaetano,

Thanks to ImportOperator::save_eZ_attribute, I discovered what I was waited for :

$contentObjectAttribute->fromString( $value );

Where $contentObjectAttribute is retrieved from :


after a simple :

$object = eZContentObject::fetchByNodeID($node_id);

The values are correctly updated !

Thank you again.

Laurent Dorier

Monday 25 January 2010 12:52:46 am


I'm trying to do the same (not for a cronjob but for an eZ extension) but unsuccesful...

$object= eZContentObject::fetchByNodeID($node_id);
$dataMap = $object->dataMap();
$contentObjectAttribute = ImportOperator::save_eZ_attribute($dataMap['MyObject_relation_list']);
$value = '206-207-213';
$contentObjectAttribute->fromString( $value );

I get:

Non-static method ImportOperator::save_eZ_attribute() should not be called statically

Someone can help ?


Monday 25 January 2010 1:12:44 am

Hi Laurent,

I have not used directly the classes from the extensions but I have extract it to my own class.

save_eZ_attribute is not static so, you should call it from an ImportOperator instance :

function save_eZ_attribute( $contentObjectAttribute )

Otherwise, this my version of the method :

 * Sauve un attribut eZ d'un objet avec une nouvelle valeur.
 * Cette méthode à l'avantage de gérer complétement les ObjectRelations et les RelationList.
 * \arg $contentObjectAttribute Pointeur sur un attribut d'un objet
 * \arg $value La valeur au format TXT
 * \author Mugo Web Copyright (C) 2008 => extension data_import (
function save_eZ_attribute( $contentObjectAttribute, $value )
    switch( $contentObjectAttribute->attribute( 'data_type_string' ) )
        case 'ezobjectrelation':
            // Remove any exisiting value first from ezobjectrelation
            eZContentObject::removeContentObjectRelation( $contentObjectAttribute->attribute('data_int'),
            $contentObjectAttribute->setAttribute( 'data_int', 0 );
        case 'ezobjectrelationlist':
            // Remove any exisiting value first from ezobjectrelationlist
            $content = $contentObjectAttribute->content();
            $relationList =& $content['relation_list'];
            $newRelationList = array();
            for ( $i = 0; $i < count( $relationList ); ++$i )
                $relationItem = $relationList[$i];
                eZObjectRelationListType::removeRelationObject( $contentObjectAttribute, $relationItem );
            $content['relation_list'] =& $newRelationList;
            $contentObjectAttribute->setContent( $content );
    // fromString returns false - even when it is successfull
    // create a bug report for that
    $contentObjectAttribute->fromString( $value );

I hope this will help you.


Laurent Dorier

Monday 25 January 2010 1:54:38 am

Thanks a lot Damien,

working like a charm. :)

But finally... I do it without this extension using the eZContentObject class...
Thanks anyway for your very fast answer.

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

36 542 Users on board!

Forums menu