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.

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 18 2025 11:07:11
Script start
Timing: Jan 18 2025 11:07:11
Module start 'layout'
Timing: Jan 18 2025 11:07:11
Module start 'content'
Timing: Jan 18 2025 11:07:11
Module end 'content'
Timing: Jan 18 2025 11:07:11
Script end

Main resources:

Total runtime0.0192 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0078 589.0313152.6250
Module start 'layout' 0.00780.0038 741.656339.4453
Module start 'content' 0.01160.0054 781.101689.3359
Module end 'content' 0.01700.0021 870.437534.3047
Script end 0.0191  904.7422 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002714.1451140.0002
Check MTime0.00115.7199140.0001
Mysql Total
Database connection0.00073.728310.0007
Mysqli_queries0.004523.224130.0015
Looping result0.00000.114410.0000
Template Total0.00178.710.0017
Template load0.00105.021310.0010
Template processing0.00073.687310.0007
Override
Cache load0.00063.379010.0006
General
dbfile0.00021.260680.0000
String conversion0.00000.058440.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