This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » Developer » Saving 'ezselection' attribute value...

Saving 'ezselection' attribute value using the 'createAndPublishObject' method

Saving 'ezselection' attribute value using the 'createAndPublishObject' method

Wednesday 22 February 2012 1:57:34 am - 3 replies


I'm writing a small script to import content into eZ Publish from a external MYSQL database. It's all working fine expect the value I'm saving for an 'ezselection' type attribute is not being stored. My code is as follows:

$user = eZUser::fetchByEmail('myemailaddress');
    $user = eZUser::currentUser();

$params = array();
$params['class_identifier'] = 'route';
$params['creator_id'] = $user->attribute('contentobject_id');
$params['parent_node_id'] = 298;
$params['section_id'] = 9;
$attributesData = array();
$attributesData['route_code'] = "routecode"; 
$attributesData['inbound_route_name'] = "inbound name"; 
$attributesData['outbound_route_name'] = "outbound name"; 
$attributesData['route_description'] = "description";
$attributesData['route_color'] = "4444444";
$attributesData['mode_type'] = "1"; //This is the ezselection attribute, so I'm passing the selection index of the value I want used.
$params['attributes'] = $attributesData;
$contentObject = eZContentFunctions::createAndPublishObject($params);

I've checked the database for what should be stored in the 'data_text' field for that attribute and it should just be the value index. So i'm baffled as to why it's not working.

After I run the import script, the new object shows up in the CMS but there is just no value set for the 'mode_type' attribute.

Thanks in advance!


Wednesday 22 February 2012 2:13:40 am

Hey Josh,
have you tried using the option value (spelled exactly like in your class attribute) when saving the selection attribute?

 $attributesData['mode_type'] = "My option value";

If you're doing more involved importing, you may want to have a look at the data_import extension
From the fromString.html doc in the extension (data_import/doc/fromString.html#selection)

quote data type string
Expected input
List of selected items names, separated by a pipe. Given values have to be defined for this selection attribute.
Value 1|Value 2|Value3
Selects '''existing''' options named "Value 1", "Value 2" and "Value 3" for the attribute.

Modified on Wednesday 22 February 2012 2:21:57 am by Benjamin Kroll

Wednesday 22 February 2012 2:21:19 am

Wow, that works. I'm sure I tried that but I think it may be case sensitive.

Thanks mate!

Wednesday 22 February 2012 2:24:18 am

Have a look at the doc I mentioned in the edited version of my reply (fromString.html). It has saved me a fair few headaches, when I have forgotten yet again how to 'feed' the attributes to the create methods happy.gif Emoticon

If you could, tick the 'Mark as solved' bubble at the top of the thread.

Modified on Wednesday 22 February 2012 2:25:25 am by Benjamin Kroll


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

36 542 Users on board!

Forums menu

Proudly Developed with from