Jump to:

23478 Posts in 18950 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » the method 'fortemplate' does not exist on 'ArrayList'

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1418 Views
  • Fraser
    Avatar
    Community Member
    46 Posts

    the method 'fortemplate' does not exist on 'ArrayList' Link to this post

    In Silverstripe 3, how can I run custom SQL and return the result for handling in my template? So far, I have:

    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();
    //return $result;
    //$dataObject = new DataList();
    $dataObject = new ArrayList();
    foreach($result as $row) {
    $dataObject->push(new ArrayData($row));
    }
    return $dataObject;

    }


    However, this is giving me the error:

    Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'ArrayList'

    What am I doing wrong here and how can I get the result of this query into my template?

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: the method 'fortemplate' does not exist on 'ArrayList' Link to this post

    You can't simply use $Listings since as it says, it hasn't got a clue how to 'output' that to your template.

    Make sure you have your template like <% loop $Listings %>..<% end_loop %>

    1418 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.