Version 3 end of life
This version of Silverstripe CMS will not recieve any additional bug fixes or documentation updates. Go to documentation for the most recent stable version.

Managing Lists

Whenever using the ORM to fetch records or navigate relationships you will receive an SS_List instance commonly as either DataList or RelationList. This object gives you the ability to iterate over each of the results or modify.

Iterating over the list.

SS_List implements IteratorAggregate, allowing you to loop over the instance.

	$members = Member::get();

	foreach($members as $member) {
		echo $member->Name;
	<% loop $Members %>
		<!-- -->
	<% end_loop %>
	// $list->find($key, $value);

	$members = Member::get();

	echo $members->find('ID', 4)->FirstName;
	// returns 'Sam'


A map is an array where the array indexes contain data as well as the values. You can build a map from any list

	$members = Member::get()->map('ID', 'FirstName');
	// $members = array(
	//	1 => 'Sam'
	//	2 => 'Sig'
	//	3 => 'Will'
	// );

This functionality is provided by the SS_Map class, which can be used to build a map around any SS_List.

	$members = Member::get();
	$map = new SS_Map($members, 'ID', 'FirstName');


	$members = Member::get();

	echo $members->column('Email');

	// returns array(
	//	'',
	//	'',
	//	''
	// );

ArrayList exists to wrap a standard PHP array in the same API as a database backed list.

	$sam = Member::get()->byId(5);
	$sig = Member::get()->byId(6);

	$list = new ArrayList();

	echo $list->Count();
	// returns '2'

API Documentation