On this page
Class TreeIterator
A Recursive iterator used to flatten nested structures and also exposes all Collection methods
- RecursiveIteratorIterator implements Iterator, Traversable, OuterIterator
 
 Cake\Collection\Iterator\TreeIterator uses Cake\Collection\CollectionTrait
   
Inherited Constants
CATCH_GET_CHILD,CHILD_FIRST,LEAVES_ONLY,SELF_FIRST
Properties summary
- 
    
$_modeprotectedThe iteration modeinteger 
Method Summary
- 
    __construct() publicConstructor
 - 
    printer() public
Returns another iterator which will return the values ready to be displayed to a user. It does so by extracting one property from each of the elements and prefixing it with a spacer so that the relative position in the tree can be visualized.
 
Method Detail
__construct()source public
__construct( RecursiveIterator $items , integer $mode Cake\Collection\Iterator\RecursiveIteratorIterator::SELF_FIRST , integer $flags 0 )
   Constructor
Parameters
- 
     RecursiveIterator 
$items - The iterator to flatten.
 - 
     integer 
$modeoptional Cake\Collection\Iterator\RecursiveIteratorIterator::SELF_FIRST - Iterator mode.
 - 
     integer 
$flagsoptional 0 - Iterator flags.
 
Overrides
RecursiveIteratorIterator::__construct()
  printer()source public
printer( string|callable $valuePath , string|callable|null $keyPath null , string $spacer '__' )
   Returns another iterator which will return the values ready to be displayed to a user. It does so by extracting one property from each of the elements and prefixing it with a spacer so that the relative position in the tree can be visualized.
Both $valuePath and $keyPath can be a string with a property name to extract or a dot separated path of properties that should be followed to get the last one in the path.
Alternatively, $valuePath and $keyPath can be callable functions. They will get the current element as first parameter, the current iteration key as second parameter, and the iterator instance as third argument.
Example
$printer = (new Collection($treeStructure))->listNested()->printer('name');
   Using a closure:
$printer = (new Collection($treeStructure))
     ->listNested()
     ->printer(function ($item, $key, $iterator) {
         return $item->name;
     });
   Parameters
- 
     string|callable 
$valuePath - 
     
The property to extract or a callable to return the display value
 - 
     string|callable|null 
$keyPathoptional null - 
     
The property to use as iteration key or a callable returning the key value.
 - 
     string 
$spaceroptional '__' - 
     
The string to use for prefixing the values according to their depth in the tree
 
Returns
Cake\Collection\Iterator\TreePrinterMethods used from Cake\Collection\CollectionTrait
_unwrap()source public
_unwrap( )
   Backwards compatible wrapper for unwrap()
Deprecated
Returns
Iteratorappend()source public
append( $items )
  cartesianProduct()source public
cartesianProduct( callable $operation null , callable $filter null )
   Returns
Cake\Collection\CollectionInterfacechunk()source public
chunk( $chunkSize )
  combine()source public
combine( $keyPath , $valuePath , $groupPath null )
  compile()source public
compile( $preserveKeys true )
  contains()source public
contains( $value )
  countBy()source public
countBy( $callback )
  each()source public
each( callable $c )
  every()source public
every( callable $c )
  extract()source public
extract( $matcher )
  first()source public
first( )
  firstMatch()source public
firstMatch( array $conditions )
  groupBy()source public
groupBy( $callback )
  indexBy()source public
indexBy( $callback )
  isEmpty()source public
isEmpty( )
  jsonSerialize()source public
jsonSerialize( )
  last()source public
last( )
  listNested()source public
listNested( $dir 'desc' , $nestingKey 'children' )
   Returns
Cake\Collection\Iterator\TreeIteratormatch()source public
match( array $conditions )
  max()source public
max( $callback , $type SORT_NUMERIC )
  min()source public
min( $callback , $type SORT_NUMERIC )
  nest()source public
nest( $idPath , $parentPath , $nestingKey 'children' )
  reduce()source public
reduce( callable $c , $zero null )
  sample()source public
sample( $size 10 )
  shuffle()source public
shuffle( )
  skip()source public
skip( $howMany )
  some()source public
some( callable $c )
  sortBy()source public
sortBy( $callback , $dir SORT_DESC , $type SORT_NUMERIC )
  sumOf()source public
sumOf( $matcher null )
  take()source public
take( $size 1 , $from 0 )
  through()source public
through( callable $handler )
  toArray()source public
toArray( $preserveKeys true )
  toList()source public
toList( )
  unfold()source public
unfold( callable $transformer null )
  unwrap()source public
unwrap( )
  zip()source public
zip( $items )
  zipWith()source public
zipWith( $items , $callable )
  Properties detail
© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
 https://api.cakephp.org/3.3/class-Cake.Collection.Iterator.TreeIterator.html