eZ Community » Forums » Developer » How to fetch objects in PHP on...
expandshrink

How to fetch objects in PHP on specified attributes ?

How to fetch objects in PHP on specified attributes ?

Thursday 30 June 2005 9:25:16 pm - 3 replies

I have a class named <i>CommandLine</i> that have the following custom attributes:

* price
* product_id
* quantity
* ...

I have to fetch all <b>CommandLine</b> that have, for example, product_id <b>100</b>.

At this time, the following code gives me all CommandLine objects :

$contentObject = eZContentObject::fetchList( true,
    array( 'contentclass_id' => 43 ) );

Do I need to proceed this way, fetching all attributes and then filtering (in PHP) on results or is it possible to use the $conditions parameter or any other techniques (SQL,...) ?

Any help would be greatly appreciated happy.gif Emoticon

Thanks in advance!

Modified on Wednesday 10 August 2005 5:48:36 pm by Patrick ALLAERT

Friday 01 July 2005 10:56:33 am

you can filter on attributes using the eZContentObjectTreeNode::subTree() function

ex:

$params = array(
 'ClassFilterType' => 'include',
 'ClassFilterArray' => 'CommandLine',
 'AttributeFilter' => array( array(
 'CommandLine/product_id', 'eq', 100 ) )
); // assuming that CommandLine is the identifier of your class

$nodeList =& eZContentObjectTreeNode::subTree($params, $parentNodeId); // where $parentNodeId is the root node or whatever...

Friday 01 July 2005 12:29:55 pm

Thank you very much perrin !

This is exactly what I needed! Just a few corrections to fit my business:

'ClassFilterArray' => 'CommandLine' --> 'ClassFilterArray' => array( 'commandline' )
'eq' --> '='

Here the final result for reuse:

$params = array(
'ClassFilterType' => 'include',
'ClassFilterArray' => array( 'commandline' ),
'AttributeFilter' => array( array(
'commandeline/product_id', '=', 100 ) )
); // assuming that CommandLine is the identifier of your class
        
$nodeList =& eZContentObjectTreeNode::subTree( $params , $parentNodeId ); // where $parentNodeId is the root node or whatever...

Modified on Friday 01 July 2005 2:47:00 pm by Patrick ALLAERT

Sunday 13 September 2009 8:55:34 pm

This was very usefull.

But for 4.1.3 you have to use:

eZContentObjectTreeNode::subTreeByNodeId( $searchParams, $nodeID)

Modified on Sunday 13 September 2009 8:57:40 pm by Christoph von Siebenthal

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu