在 Silverstripe 3 中,我正在尝试运行一些自定义 SQL 并返回结果以在我的模板中进行处理:
function getListings(){
$sqlQuery = new SQLQuery();
$sqlQuery->setFrom('ListingCategory_Listings');
$sqlQuery->selectField('*');
$sqlQuery->addLeftJoin('Listing', '"ListingCategory_Listings"."ListingID" = "Listing"."ID"');
$sqlQuery->addLeftJoin('SiteTree_Live', '"Listing"."ID" = "SiteTree_Live"."ID"');
$sqlQuery->addLeftJoin('ListingCategory', '"ListingCategory_Listings"."ListingCategoryID" = "ListingCategory"."ID"');
$sqlQuery->addLeftJoin('File', '"ListingCategory"."IconID" = "File"."ID"');
$result = $sqlQuery->execute();
$dataObject = new ArrayList();
foreach($result as $row) {
$dataObject->push(new ArrayData($row));
}
return $dataObject;
}
但是,这给了我错误:
未捕获的异常:Object->__call():“ArrayList”上不存在“fortemplate”方法
我在这里做错了什么,如何将此查询的结果放入我的模板中?