21277 Posts in 5728 Topics by 2599 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1088 Views |
-
DataObject::get() returns null

22 April 2010 at 7:05pm Last edited: 22 April 2010 7:10pm
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?
| 1088 Views | ||
|
Page:
1
|
Go to Top |

