looking for a better way of writing this code...

Author Message

Pascal Specht

Thursday 30 August 2007 7:26:29 am

Hi all,

I need to access a Matrix which I defined in the backend in the Common INI Settings class.

I can do it this way:

			$chosenNode = eZContentObject::fetch( 52 ) ;
			$dataMap = $chosenNode->dataMap();
			$matrix=$dataMap['my_matrix']->content();

but obviously, I have hardcoded the instance ID of the Common INI Settings class, and I feel bad doing this kind of things.

What would be a better way of getting to this class, without hard wiring the ID? Is it safe to assume this will be 52 in the feature?

Thanks in advance for your help,
-Pascal

André R.

Thursday 30 August 2007 8:06:37 am

No, the id is actually 54 on ezwebin sites.
Try doing something like this:

$classID = eZContentObjectTreeNode::classIDByIdentifier( 'template_look' );
$obj = eZContentObject::fetchFilteredList( array( 'contentclass_id' => $classID ), 0, 1 );
$dataMap = $obj->dataMap();
$matrix = $dataMap['my_matrix']->content();

PS: The first line is cached by ez publish, so normally no database lookup.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Pascal Specht

Thursday 30 August 2007 8:34:09 am

Hi André,

Thank you very much. That was indeed what I was looking for!

		$classID = eZContentObjectTreeNode::classIDByIdentifier( 'common_ini_settings' );
		$chosenNodeList    = eZContentObject::fetchFilteredList( array( 'contentclass_id' => $classID ), 0, 1 );
		$chosenNode = $chosenNodeList[0];

-Pascal

André R.

Thursday 30 August 2007 11:32:10 am

Ahh, forgot that it's a array, my bad ;)
But its a array of content objects, not nodes.

$classID = eZContentObjectTreeNode::classIDByIdentifier( 'common_ini_settings' );
$chosenObjectList   = eZContentObject::fetchFilteredList( array( 'contentclass_id' => $classID ), 0, 1 );
$chosenObject = $chosenObjectList[0];

Nodes are what you get when use the eZContentObjectTreeNode fetch functions.
Or fetching it from the object like this:

$chosenMainNode = $chosenObject->attribute('main_node');

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

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

Main resources:

Total runtime0.0233 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.0056 589.1797152.6406
Module start 'layout' 0.00560.0031 741.820339.4766
Module start 'content' 0.00870.0120 781.296993.4922
Module end 'content' 0.02070.0025 874.789134.3047
Script end 0.0232  909.0938 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.004217.9511140.0003
Check MTime0.00135.6766140.0001
Mysql Total
Database connection0.00114.886310.0011
Mysqli_queries0.002711.409530.0009
Looping result0.00000.086010.0000
Template Total0.00187.910.0018
Template load0.00114.813610.0011
Template processing0.00073.069110.0007
Override
Cache load0.00083.542110.0008
General
dbfile0.003113.279880.0004
String conversion0.00000.036940.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