Object Name Pattern: how to use it in PHP script

Author Message

Jim Reverend

Friday 06 February 2004 7:42:14 am

For each defined class, there is an "Object Name Pattern" field that is a method of telling the Object how to get its name from the data in the object.

In the Article class, the object name pattern is "<title>". Yet, when I create a new Object of class "Article" via PHP, one might think that the name would have to be set manually, like so:
******************************************************
$contentclass =& ezcontentclass::fetch($params['comment']['objtype']);
$contentobject =& $contentclass->instantiate($params['auth'],$params['comment']['section']);
$version =& $contentobject->version( $contentobject->attribute('current_version') );
$contentobjectdatamap =& $version->datamap();

/* Store the Title */
$contentobjectdatamap['title']->setAttribute('data_text',$data['title']);
$contentobjectdatamap['title']->store();

/* Store the Title Again */
$contentobject->setName($data['title']);

$version->store();
$contentobject->store();
********************************************************

However, this is not the case. The ezContentClass has a method named contentObjectName() that follows the rules defined in the class. Therefore, instead of setting the name of the content object as you say above, instead, one should do the following:

*******
$contentobject->setName($contentclass->contentObjectName($contentobject), $version->attribute('version'));
*******

I hope this helps someone.

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 19 2025 03:17:59
Script start
Timing: Jan 19 2025 03:17:59
Module start 'layout'
Timing: Jan 19 2025 03:17:59
Module start 'content'
Timing: Jan 19 2025 03:18:01
Module end 'content'
Timing: Jan 19 2025 03:18:01
Script end

Main resources:

Total runtime1.2980 sec
Peak memory usage4,096.0000 KB
Database Queries46

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0064 589.2891152.6406
Module start 'layout' 0.00640.0044 741.929739.4766
Module start 'content' 0.01081.2857 781.4063412.4141
Module end 'content' 1.29650.0014 1,193.82038.1250
Script end 1.2979  1,201.9453 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.2500160.0002
Check MTime0.00150.1150160.0001
Mysql Total
Database connection0.00080.063810.0008
Mysqli_queries1.253296.5555460.0272
Looping result0.00060.0447440.0000
Template Total1.239295.520.6196
Template load0.00230.176120.0011
Template processing1.236995.297920.6185
Template load and register function0.00010.010710.0001
states
state_id_array0.00240.187610.0024
state_identifier_array0.00540.417420.0027
Override
Cache load0.00180.1383230.0001
Sytem overhead
Fetch class attribute can translate value0.00080.060510.0008
Fetch class attribute name0.00080.064910.0008
XML
Image XML parsing0.00010.007910.0001
class_abstraction
Instantiating content class attribute0.00000.000310.0000
General
dbfile0.00070.0541100.0001
String conversion0.00000.000840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
1content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 14
 Number of unique templates used: 5

Time used to render debug report: 0.0001 secs