Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

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

DataObject::get_one() fails even if the object exists & matches criteria


2 Posts   1042 Views

Ryan M.

2 September 2010 at 9:29pm (Last edited: 2 September 2010 9:32pm), Community Member, 309 Posts

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;


4 September 2010 at 8:46pm Forum Moderator, 5511 Posts

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"));