Forums / Setup & design / looking for a better way of writing this code...

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

eZ debug

Timing: Jan 31 2025 03:27:06
Script start
Timing: Jan 31 2025 03:27:06
Module start 'content'
Timing: Jan 31 2025 03:27:06
Module end 'content'
Timing: Jan 31 2025 03:27:06
Script end

Main resources:

Total runtime0.0321 sec
Peak memory usage4,096.0000 KB
Database Queries4

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0086 588.0625370.2734
Module start 'content' 0.00860.0140 958.33591,005.7031
Module end 'content' 0.02260.0094 1,964.039174.7031
Script end 0.0321  2,038.7422 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00257.8355120.0002
Check MTime0.00113.4183120.0001
Mysql Total
Database connection0.00123.632010.0012
Mysqli_queries0.00329.838540.0008
Looping result0.00000.059420.0000
Template Total0.008927.710.0089
Template load0.00103.047210.0010
Template processing0.007924.652310.0079
Override
Cache load0.00051.680910.0005
General
dbfile0.005115.8283100.0005
String conversion0.00000.019330.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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