Hi. I have a problem with searching through DataObjects.
My code looks like:
function search() {
$phrase = Director::urlParam("ID");
$filter = "`ParentPageID` = '".Director::currentPage()->ID."' AND `Content` LIKE '%".$phrase."%'";
$items = DataObject::get('MyObject',$filter);
$data = array( "Results" => $items );
return $this->customise($data)->renderWith('SearchResults');
}
And the template:
<% if Results %>
<p>Results</p>
<% else %>
<p>No results</p>
<% end_if %>
When the $phrase is found, everything works perfect. But when the $phrase filter doesn't match any objects, the template goes blank.
Checking $items->Count() doesn't help, it looks like the renderer doesn't work when no objects are found.
What does DataObject::get() return when the filter param doesn't match anything?
How can I make this work?