Silverstripe Version: 4.4.x-dev
Question: I get the error
Uncaught BadMethodCallException: Object->__call(): the method 'forTemplate' does not exist on 'SilverStripe\ORM\ArrayList when I passed the results obtained from a searchFrom object to a function. What can I do to fix this?'
Following the instructions here, I have implemented a search function for my site: https://docs.silverstripe.org/en/3/tutorials/site_search/ (I know this is for the previous version of silverstripe, but for some reason it mostly works). The only problem is that some search results aren’t correct (ie. the query searched is not contained within the page). To correct this, I wrote a function to filter out pages that are returned but not correct. The only problem is that when I try to pass the results returned by the searchForm to this filtering function, I get the error
Uncaught BadMethodCallException: Object->__call(): the method 'forTemplate' does not exist on 'SilverStripe\ORM\ArrayList. The issue is with my code in the template. I know this because I have tested passing the results to an empty function and it still results in the same error. I’m not really sure what to do to fix this.
Here is the code I have in
Page_results.ss that causes the issue:
<% loop filterResults($Results) %> <% end_loop %>
If instead of passing
$Results, I pass garbage (ex. “foo”), then I don’t get the error, so I know this is what is causing it.