This is the code here, it is grabbing records from the pageview table that records page views. Its returning the id fine, now I just need to get the url and page name so I can use them in the view.
Sorry I should have started with this...
public function MostViewed($limit = 5) {
//Returns a list of page id's
$ID = PageView::get()
->sort('Count', 'DESC');
/*loop through each of the records retrieved and grab the link by matching the page id to the
* corresponding data object.
*/
foreach ($ID as $id){
//get the page id from the retrieved record
$PageId = $id->PageID;
$DataObject = DataObject::get("Page", "`ID` = '$PageId'");
}
//should be returning the page url here or object to retrieve the url from
return $ID;
}