Forums / General / Fetch By Attribute Value

Fetch By Attribute Value

Author Message

Carlos Revillo

Thursday 01 June 2006 6:32:13 am

Hi. Now i'm working with a extension and i need to write php code to fetch nodes by one of their attributes.

i can't find a method in the documentation for that.

i'm searching for something like eZContentObjectTreeNode::fetchNodesByPathString, but i can't find anything...

any ideas?

Kristof Coomans

Thursday 01 June 2006 11:34:12 pm

Hi Carlos

You can use something like

include_once( 'lib/ezutils/classes/ezfunctionhandler.php' );
$nodes = eZFunctionHandler::execute('content','tree', $params );

where $params is an associative array with the same keys as you can use for the content/tree fetch function ( http://ez.no/doc/ez_publish/technical_manual/3_8/reference/modules/content/fetch_functions/tree ) in the templates. Then you can use the attribute_filter key to filter on attributes.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Carlos Revillo

Monday 05 June 2006 3:13:17 am

Great!. Works perfectly. Thanks a lot.

Montel Sébastien

Thursday 08 June 2006 8:58:46 am

Hi,

I try to manipulate the eZFunctionHandler class but it doesn't work. With eZContentObjectTreeNode, i fetch the nodes for example below node number 2.

include_once ('kernel/classes/ezcontentobjecttreenode.php');
$nodes =& eZContentObjectTreeNode::subTree(array('Depth'=>1),2);

To obtain the same result with eZFunctionHandler class, i use

include_once ('lib/ezutils/classes/ezfunctionhandler.php');
$nodes = eZFunctionHandler::execute('content','list', array('parent_node_id' => 2) );

But in this case, nothing in result. Where do i make a mistake ?

thanks,
Sébastien

Kristof Coomans

Thursday 08 June 2006 10:28:58 am

What exactly do you get back?

var_dump( $nodes );

Do you get any PHP errors/warnings in the debug output?

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Łukasz Serwatka

Thursday 08 June 2006 2:04:13 pm

Hmm, I think you were testing the fetch from the CLI script, right? ;)

Then you need to tell script to use modules:

replace line:

$script =& eZScript::instance();

with:

$script =& eZScript::instance( array( 'use-modules' => true ) );

Then it will work.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Montel Sébastien

Thursday 08 June 2006 11:38:30 pm

Hi Lukasz,

you're right, i want to fetch data from the CLI script ... your help was useful ! it works ... (thanks a lot for your article "about Fetching eZ publish content objects with PHP", it's nice to understand kernel ... :-) )

merci !

Sébastien

Łukasz Serwatka

Thursday 08 June 2006 11:59:42 pm

You are welcome Sébastien ;) I have posted comment about this under the tutorial for future readers.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog