Forums / Developer / Creating an article on the fly

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

Creating an article on the fly

Author Message

Fabien Mas

Friday 13 April 2007 12:19:46 am

Hi everybody,

I have some data that I want to insert in a new article, manually with the code
How do I process ?

thx, Fabien

Jacques Feix

Friday 13 April 2007 6:03:09 am

Here is a sample of my own ;)

	$elementClass=eZContentClass::fetchByIdentifier("article");
	$classAttributes =& $elementClass->fetchAttributes();

	$element =& $elementClass->instantiate($userID,$sectionID,false,$languageCode);
        $elementID = $element->attribute('id');

	$nodeAssignement =& eZNodeAssignment::create
	        (array('contentobject_id' => $elementID,
	               'contentobject_version' => $element->attribute('current_version'),
	               'parent_node' => $parentID,
	               'is_main' => 1));
	$nodeAssignement->store();
	
	$elementVersion =& $element->version($element->attribute('current_version'));
	$elementVersion->setAttribute('status', EZ_VERSION_STATUS_DRAFT);
	$elementVersion->store();

	$datamap = $elementVersion->dataMap();

	    // Titre
	    $attribute = $datamap["title"];
	    $attribute->setAttribute('data_text', $this->Nom);
	    $attribute->store();

	    // short_title
	    $attribute = $datamap["short_title"];
	    $attribute->setAttribute('data_text', $this->Nom);
	    $attribute->store();
//.... other attributes ..

	    $operationResult =& eZOperationHandler::execute
	          ('content', 'publish',
	           array('object_id' => $elementID,
	             'version' => $element->attribute('current_version')));

nehal shah

Thursday 20 January 2011 12:09:01 am

Hi guyz

I have the same problem, i m trying to insert article programatically . i tried above code in my eZ-Publish(4.3) but it doesn't work. Please help me out.