Jump to:

23479 Posts in 18951 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » DataObject::get() returns null

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1307 Views
  • k0m0r
    Community Member
    39 Posts

    DataObject::get() returns null Link to this post

    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 %>
    <% 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?

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.