src/Model/Behavior/AncestorBehavior.php
public function getMultilevelChildren($id, array $options = [])
	{
		$options['for']    = $id;
		$options['direct'] = false;

		$options['for']    = $id;
		$options['direct'] = false;

		$query    = $this->_table->find();
		$iterator = $this->findChildren($query, $options);

		$primaryKey = $this->_table->getSchema()->primaryKey();
		$primaryKey = count($primaryKey) == 1 ? $primaryKey[0] : $primaryKey;

		$parent_id_fieldname = $this->getConfig('model_parent_id_fieldname');

		$nodes_by_pk = [];
		$root_nodes  = [];

		foreach($iterator as $node)
		{
			$nodes_by_pk[$node->{$primaryKey}] = $node;

			if($node->{$parent_id_fieldname} == $id)
			{
				$root_nodes[] = $node;
			}

			if(isset($nodes_by_pk[$node->{$parent_id_fieldname}]))
			{
				if(!isset($nodes_by_pk[$node->{$parent_id_fieldname}]->children))
				{
					$nodes_by_pk[$node->{$parent_id_fieldname}]->children = [];
				}

				$nodes_by_pk[$node->{$parent_id_fieldname}]->children[] = $node;
			}
		}
		unset($node);

		return new \Cake\Collection\Collection($root_nodes);
	}
public function getMultilevelChildren($id, array $options = [])
	{
		$options['for']    = $id;
		$options['direct'] = false;

		$options['for']    = $id;
		$options['direct'] = false;

		$query    = $this->_table->find();
		$iterator = $this->findChildren($query, $options);

		$primaryKey = $this->_table->getSchema()->primaryKey();
		$primaryKey = count($primaryKey) == 1 ? $primaryKey[0] : $primaryKey;

		$parent_id_fieldname = $this->getConfig('model_parent_id_fieldname');

		$nodes_by_pk = [];
		$root_nodes  = [];

		foreach($iterator as $node)
		{
			$nodes_by_pk[$node->{$primaryKey}] = $node;

			if($node->{$parent_id_fieldname} == $id)
			{
				$root_nodes[] = $node;
			}

			if(isset($nodes_by_pk[$node->{$parent_id_fieldname}]))
			{
				if(!isset($nodes_by_pk[$node->{$parent_id_fieldname}]->children))
				{
					$nodes_by_pk[$node->{$parent_id_fieldname}]->children = [];
				}

				$nodes_by_pk[$node->{$parent_id_fieldname}]->children[] = $node;
			}
		}
		unset($node);

		return new \Cake\Collection\Collection($root_nodes);
	}
public function getMultilevelChildren ( $ id , array $ options = [ ] ) { $ options [ 'for' ] = $ id ; $ options [ 'direct' ] = false ; $ options [ 'for' ] = $ id ; $ options [ 'direct' ] = false ; $ query = $ this -> _table -> find ( ) ; $ iterator = $ this -> findChildren ( $ query , $ options ) ; $ primaryKey = $ this -> _table -> getSchema ( ) -> primaryKey ( ) ; $ primaryKey = count ( $ primaryKey ) == 1 ? $ primaryKey [ 0 ] : $ primaryKey ; $ parent_id_fieldname = $ this -> getConfig ( 'model_parent_id_fieldname' ) ; $ nodes_by_pk = [ ] ; $ root_nodes = [ ] ; foreach ( $ iterator as $ node ) { $ nodes_by_pk [ $ node -> { $ primaryKey } ] = $ node ; if ( $ node -> { $ parent_id_fieldname } == $ id ) { $ root_nodes [ ] = $ node ; } if ( isset ( $ nodes_by_pk [ $ node -> { $ parent_id_fieldname } ] ) ) { if ( ! isset ( $ nodes_by_pk [ $ node -> { $ parent_id_fieldname } ] -> children ) ) { $ nodes_by_pk [ $ node -> { $ parent_id_fieldname } ] -> children = [ ] ; } $ nodes_by_pk [ $ node -> { $ parent_id_fieldname } ] -> children [ ] = $ node ; } } unset ( $ node ) ; return new \ Cake \ Collection \ Collection ( $ root_nodes ) ; }
Return a multi-dimension array of child nodes

@param int $id
@param array $options
@return \Cake\Collection\Collection
Return a multi - dimension array of child nodes