Wanted: documentation on creating contentObjects from scratch

Author Message

Gabriel Ambuehl

Tuesday 06 May 2003 8:22:27 am

I'm trying to create content objects from scratch but when I look at http://ez.no/sdk/kernel/view/content_objects I have my trouble figuring out how to add attributes as the page only changes an existing object with existing attributes.

From what I can tell, I need to call
$new_content_object=(eZContentObject::create($name,$contentclassID,$userID,$sectionID));
to store a new object in my var.

Now I can call
$new_content_object->store();
to store it in the db.

But how can I store add attributes? Or fetch what attribute the content class I'm working with is supposed to provide, anyway?

$new_content_object->contentObjectAttributes()
returns an empyt array, so that can't be it.

Some more documentation (like the contentClass docs which are superb) for contentobject and contentobjectattribute would be very helpful. Especially SIMPLE, non-generic (genericity always adds A LOT of complexity) examples would be nice.

Visit http://triligon.org

Paul Borgermans

Tuesday 06 May 2003 9:19:17 am

Gabriel,

I use the following source to study this. Maybe it helps you too:

http://zev.ez.no/svn/nextgen/trunk/scrap/rotaryimport.php

I agree on your request for better docs, which is one of the priorities of the ez team now.

Paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Gabriel Ambuehl

Friday 09 May 2003 8:40:36 am

Ok, so I have:
----------
$class =& eZContentClass::fetch( 28 );
// Create object by userid in sectionid
$contentObject =& $class->instantiate( $userID, $sectionID );

$nodeAssignment =& eZNodeAssignment::create( array(
'contentobject_id' => $contentObject->attribute( 'id' ),
'contentobject_version' => $contentObject->attribute( 'current_version' ),
'parent_node' => 1,
'is_main' => 1
)
);

$version =& $contentObject->version( 1 );
$contentObjectAttributes =& $version->contentObjectAttributes();

$contentObjectAttributes[0]->setContent( $structure->headers['from'] );
$contentObjectAttributes[0]->store();

$version->setAttribute( 'modified', eZDateTime::currentTimeStamp() );
$version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
$version->setAttribute( 'name', $name );

$version->store();
$contentObject->store();
$nodeAssignment->store();

$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject->attribute( 'id' ), 'version' => 1 ) );

----------

But it doesn't quite work. I'd figure that the content object should be turning up in the root node but it won't (but it DOES get added to the db)

Visit http://triligon.org

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.