This site has been archived. To learn more about our current products Ibexa Content, Ibexa Experience, Ibexa Commerce head over to the Ibexa Developer Portal

eZ Community » Forums » Developer » Copy ezimage attribute in PHP

Copy ezimage attribute in PHP

Copy ezimage attribute in PHP

Friday 28 October 2011 1:49:39 pm - 4 replies

I'm trying to copy an ezimage attribute from one object (of class say 'class1') to a new object (of class say 'class2'). What would be the best approach?I'm using eZContentFunctions::createAndPublishObject() to create the new object and populate some attributes which works well except for the ezimage attribute.Any ideas how to approach this problem?

Friday 28 October 2011 2:01:10 pm

For some ideas, see 'Importing image objects from a RSS feed', starting from the line:

if ( @fopen($item['image'],"r") ){

Modified on Friday 28 October 2011 2:02:43 pm by S V

Friday 28 October 2011 2:24:31 pm

Hi Andy,

toString/fromString combination should work fine. Something along these lines.

$content = $originalImageAttribute->toString();
$newImageAttribute->fromString( $content );

Thursday 03 November 2011 12:28:09 pm

Thanks very much! Edi's suggestion of just using toString/fromString worked AFTER creating the new object using eZContentFunctions::createAndPublishObject(). Sometimes eZ Publish is more simple than I expect, once you know how!

Thursday 03 November 2011 12:43:30 pm

Hi Andy,

Yes, that exact same lines would work only after creating an object because the attribute doesn't exist yet.

But, by modifying the code a bit, it should also work at the moment when using eZContentFunctions::createAndPublishObject() since it also uses fromString method to import images.

Like this:

$params['attributes'] = array();
$params['attributes']['my_image_attribute'] = $originalImageAttribute->toString();
eZContentFunctions::createAndPublishObject( $params );

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

36 542 Users on board!

Forums menu

Proudly Developed with from