Last active
December 10, 2015 23:39
-
-
Save dhensby/4511316 to your computer and use it in GitHub Desktop.
Create a DataObjectSet from an SS_Query - SilverStripe 2.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//2.x | |
function queryToDos(SS_Query $qry) { | |
$dos = new DataObjectSet(); | |
while ($record = $qry->next()) { | |
$dos->push(new {$record['ClassName']}($record)); | |
} | |
return $dos; | |
} | |
//3.x | |
function queryToArrayList(SS_Query $qry) { | |
$list = ArrayList::create(); | |
while ($record = $qry->next()) { | |
$list->push(Injector::inst()->create($record['ClassName'], $record)); | |
} | |
return $list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment