Hi,
I am trying to write a simple function which gets every page via the SiteTree, loops through each page and adds it to an array if included (added field in page class) = true.
I'm not particularly experienced with OO PHP and feel there's something fundamentally wrong with my code here.
function GetTopMenu() {
$AllPages = DataObject::get("SiteTree");
$IncludedPages = array();
foreach($AllPages as $Page) {//select the pages with "included = true"
array_push($IncludedPages, $Page);
}
return $IncludedPages;
}
This is just a test to see if I can take every page and put it into another array (not sure about putting objects into arrays, is that how it's done?), but returns nothing.
Any help would be greatly appreciated.
EDIT: Nevermind, got it.
function GetTopMenu() {
$AllPages = DataObject::get("SiteTree");
$OtherPages = new DataObjectSet();
foreach($AllPages as $Page) {//select the pages with "included = true"
if($Page->Included==true){
$OtherPages->push($Page);
}
}
return $OtherPages;
}