PHP content object translation

Author Message

Joël LEGER

Wednesday 02 September 2009 8:58:11 am

Hi ,

i try to create an english version from my french content object.
The only problem is when i try to set the attribute 'titre' fot the english version i got an error message : Undefined attribute 'titre', cannot set

here is the code :

$attributesData = array();
$attributesData['titre'] = 'TITRE EN FRE';
 
$params['attributes'] = $attributesData;
$contentObject = eZContentFunctions::createAndPublishObject( $params );

$engVersion = $contentObject->createNewVersion( $contentObject->CurrentVersion, true, 'eng-US', 'fre-FR' );

$contentObjectAttributes = $engVersion->contentObjectAttributes();
 
$contentObjectAttributes[0]->setAttribute( 'titre', 'TITLE ENGLISH');
$contentObjectAttributes[0]->store();

eZOperationHandler::execute( 'content', 'publish', array('object_id' => $engVersion->ContentObjectID, 'version' => $engVersion->Version ) );

Carlos Revillo

Wednesday 02 September 2009 11:49:28 am

titre is the identifier for the attribute you have defined, but it's not part of the definition of the ezcontentobjectattribute_class.

supposing 'titre' as a ezstring datatype, you could try with

...
$contentObjectAttributes[0]->setAttribute( 'data_text', 'TITLE ENGLISH');
$contentObjectAttributes[0]->store();
...

hope it helps.

Joël LEGER

Thursday 03 September 2009 2:44:14 am

yes , works fine
thx

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 21:41:57
Script start
Timing: Jan 30 2025 21:41:57
Module start 'layout'
Timing: Jan 30 2025 21:41:57
Module start 'content'
Timing: Jan 30 2025 21:41:57
Module end 'content'
Timing: Jan 30 2025 21:41:57
Script end

Main resources:

Total runtime0.0386 sec
Peak memory usage4,096.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0087 588.1328151.2109
Module start 'layout' 0.00870.0080 739.3438220.6875
Module start 'content' 0.01670.0207 960.0313997.8047
Module end 'content' 0.03740.0012 1,957.835929.9922
Script end 0.0386  1,987.8281 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00307.7225140.0002
Check MTime0.00133.3478140.0001
Mysql Total
Database connection0.00102.632010.0010
Mysqli_queries0.006115.802230.0020
Looping result0.00000.067310.0000
Template Total0.00092.310.0009
Template load0.00071.814310.0007
Template processing0.00020.450510.0002
Override
Cache load0.00051.234810.0005
General
dbfile0.005714.740280.0007
String conversion0.00000.033340.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