Silverstripe SS3:方法';fortemplate&x27;不存在于';ArrayList';
在Silverstripe 3中,我尝试运行一些自定义SQL并返回结果,以便在我的模板中进行处理:Silverstripe SS3:方法';fortemplate&x27;不存在于';ArrayList';,silverstripe,Silverstripe,在Silverstripe 3中,我尝试运行一些自定义SQL并返回结果,以便在我的模板中进行处理: function getListings(){ $sqlQuery = new SQLQuery(); $sqlQuery->setFrom('ListingCategory_Listings'); $sqlQuery->selectField('*'); $sqlQuery->addLeftJoin('Listin
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;
}
但是,这给了我一个错误:
未捕获异常:对象->\u调用():方法“fortemplate”没有
“ArrayList”上不存在
我在这里做错了什么?如何将查询结果输入模板?我没有看到您的模板代码,但我假设您只是在模板中调用
$Listings
。
这将不起作用,因为ArrayList没有forTemplate方法(forTemplate所做的是将对象作为适当的字符串输出,例如表单上的forTemplate输出html元素)
您可能要做的是循环列表并使用对象:
<% loop Listings %>
$ID
$Something
$Foobar
<% end_loop %>
$ID
美元左右
$Foobar
或者,如果对象具有该方法,则可以对其调用forTemplate:
<% loop Listings %>
$forTemplate
<% end_loop %>
$forTemplate
我没有看到您的模板代码,但我假设您只是在模板中调用$Listings
。
这将不起作用,因为ArrayList没有forTemplate方法(forTemplate所做的是将对象作为适当的字符串输出,例如表单上的forTemplate输出html元素)
您可能要做的是循环列表并使用对象:
<% loop Listings %>
$ID
$Something
$Foobar
<% end_loop %>
$ID
美元左右
$Foobar
或者,如果对象具有该方法,则可以对其调用forTemplate:
<% loop Listings %>
$forTemplate
<% end_loop %>
$forTemplate
我是个白痴。你是对的,我的模板中有$Listings作为占位符,试图让PHP工作,然后再将注意力转向模板……甚至用$Me替换$forTemplate。短即甜;)我是个白痴。你是对的,我的模板中有$Listings作为占位符,试图让PHP工作,然后再将注意力转向模板……甚至用$Me替换$forTemplate。短即甜;)