Silverstripe Version:4.4.x-dev
Question: Why is this ArrayList not updating?
In my Page
class I have an ArrayList
variable results
. In my template, the function updateResults
is called multiple times in a loop. I also have a function getResults
that just returns the results. Each time updateResults
is called, a new ArrayData
object is pushed to the ArrayList
.
Here’s the outline of my Page.php
class Page extends SiteTree {
...
private $results;
public function __construct($record = null, $isSingleton = false, $queryParams = array()) {
$this->results = new ArrayList();
parent::__construct($record, $isSingleton, $queryParams);
}
public function updateResults($title, $content) {
$this->results->push(new ArrayData(['title' => $title, 'content' => $content]));
}
public function getResults() {
return $this->results;
}
}
If I were to add foreach ($this->searchResults as $s) {echo $s->Title;}
to getResults
it would print nothing.
What can I do?