Jump to:

23456 Posts in 18905 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » weird non redirect issues

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: 654 Views
  • mattclegg
    Community Member
    56 Posts

    weird non redirect issues Link to this post


    Im using a lookup function to get a relevant object by ID like;

    $val=(search string as integer);

    $sqlQuery = new SQLQuery("COUNT(myObject.ID)","myObject","ID=".intval($val));
    return DataObject::get_by_id('myObject', intval($val));

    but instead of being redirected the function is returning null and I get;

    [Notice] Trying to get property of non-object

    Any ideas?

  • Hamish
    Community Member
    712 Posts

    Re: weird non redirect issues Link to this post

    EDIT: misread the question, let me try again:

    Why are you running an SQL Count query? The following makes a lot more sense:

    if($object = DataObject::get_by_id('myObject', intval($val)))
       return $object;

    The error is probably being caused in whatever method is calling the above code. It should check that a valid object is returned. Note that Director::redirect doesn't halt execution - so you still need to check if the method has returned a valid object before doing something with it.

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.