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.