Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8697853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:37:00+00:00 2026-06-13T01:37:00+00:00

In Silverstripe 3, I’m trying to run some custom SQL and return the result

  • 0

In Silverstripe 3, I’m trying to run some custom SQL and return the result for handling in my template:

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;

    }

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:37:00+00:00Added an answer on June 13, 2026 at 1:37 am

    I have not seen your template code, but I am assuming you are just calling $Listings in template.
    Which will not work because ArrayList has no forTemplate method (what forTemplate does is output the object as a appropriate string, for example a forTemplate on Form outputs a html element).

    You probably want to do is loop the List and use the object:

    <% loop Listings %>
        $ID
        $Something
        $Foobar
    <% end_loop %> 
    

    or, you can call forTemplate on the object if it has that method:

    <% loop Listings %>
        $forTemplate
    <% end_loop %> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SilverStripe 2.4.7 Hi I'm trying to put together a template to structure my JSON.
In SilverStripe 3, How can I put multiline comments in template file ?
Using SilverStripe 2.4.7. I've done some searching but I can't seem to be able
I've built an Ecommerce site in Silverstripe and I'm new to this, sorry if
I am trying to install this theme in SilverStripe: http://www.silverstripe.org/woody-theme/ Here is what I
I have just moved a silverstripe install to a new joyent smartos server. Not
Is it possible to set default widgets for new pages within silverstripe or have
I am trying to populate four menu items in Silverstripe. I have managed to
I have added new Sub Tabs Under The Settings->Main Tab in The Silverstripe 3.0
I'm trying to implement Recaptcha to Silverstripe, it is all working well but the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.