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