Jump to:

23013 Posts in 11540 Topics by 2825 members

General Questions

SilverStripe Forums » General Questions » DataObject::get_one() fails even if the object exists & matches criteria

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: 972 Views
  • Ryan M.
    Avatar
    Community Member
    309 Posts

    DataObject::get_one() fails even if the object exists & matches criteria Link to this post

    Is that even possible? I have the following code, but it's failing at the if statement. I did a print_r($p) to find out what it was outputting, and all it was giving up was a "1". Hmm???? And yes, I checked the database to make sure everything existed.

    BTW, the class Profile is an extension of Page.

    public function EditProfileLink() {
          $mid = Member::currentUserID();
          if($p = DataObject::get_one("Profile", "MemberID = $mid")) {
             return $p->Link('edit');
          } else
          return false;
       }

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: DataObject::get_one() fails even if the object exists & matches criteria Link to this post

    So if you do a Debug::show(DataObject::get_one("Profile", "MemberID = $mid")); does it return 1 still or just the object? How about Debug::show(DataObject::get_one("Profile"));

    972 Views
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.