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 » Learn » eZ Publish » Creating eZ Publish Objects in PHP

Creating eZ Publish Objects in PHP

Friday 04 June 2010 5:09:02 pm

  • Currently 5 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Step 3 - Adding the Content (continued)

Simple Content – A Folder (continued)

Preparing the object attributes

Code :

//setting attribute values
$attributesData = array() ;
$attributesData['name'] = 'A brand new folder' ; 
$attributesData ['short_name'] = 'Shorter name' ; 
$params['attributes'] = $attributesData;
print_r( $params ); //lets print out the data so we know exactly what is being stored

This is very straightforward, we just store the name of each attribute along with it’s value as a set of key/value pairs. Once we have done this we add it to our $params array ready for the final step…

Creating the object

Code :

//publishing the content:
$contentObject = eZContentFunctions::createAndPublishObject( $params );
if ($contentObject)
    $cli->output( '===========================' );
    $cli->output( 'Output:' );
    $cli->output( "Content Object ID: " . $contentObject->attribute( 'id' ) );
    $cli->output( "Name: " . $contentObject->attribute( 'name' ) );
    $cli->output( "Data Map: " . print_r( $contentObject->attribute( 'data_map' ), true ) );

And that is it! We have already stored all of the values that eZ Publish needs so all we need to do to publish it is send the eZContentFunctions::createAndPublishObject function the $params array. The function returns an eZContentObject which we can then use if needed. We are simply outputting it’s ID, name and the data it is storing.

Below is the output to our script. From it you can see the structure of the $params array we use to populate the object quite clearly. You can also see how easy it then is to extract the information we have just published.

Script output

Although that is a simple example it is the basis for all of the following code. To test it has worked go into the back office and verify the node has been created. The basic script is simple enough but there are a few caveats you need to be aware of. Images, files, XML and related object fields can all be added using this approach but they are slightly more complicated to import, we’ll start with XML fields and then we will work through the others:



Printer Friendly version of the full article on one page with plain styles


Proudly Developed with from