Author Topic

Kristof Coomans

Wednesday 18 November 2009 3:16:58 am

Comment55822

Interesting topic, as I faced this problem myself several times.

What about introducing a specialized implementation of PHP's Iterator interface that hides all the logic of fetching with offset and limit and clearing caches?

The example below shows how the name is displayed of all folders under node 2. After each batch of 100 nodes the iterator takes care of clearing the in-memory caches and fetches the next 100 nodes from the database.

$params = array( 'ClassFilterType' => 'include', 'ClassFilterArray' => array( 'folder' ) );

$nodeList = new eZContentObjectTreeNodeSubTreeIterator( 2, $params, 100 );

foreach ($nodeList as $node)
{
    echo $node->attribute('name');
}

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