Jump to:

3063 Posts in 864 Topics by 646 members

Data Model Questions

SilverStripe Forums » Data Model Questions » DataObject::get not working in Ajax call unless logged in as admin

Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 164 Views
  • msawebdev
    Avatar
    Community Member
    7 Posts

    DataObject::get not working in Ajax call unless logged in as admin Link to this post

    I have an AJAX call to get a list of store objects. It works fine if I am logged in as admin but returns an empty list if logged in as any other type of member or not logged in at all.

    any and all help most appreciated

    public function getStoreList(){

    if($this->isAjax) {
    if( $data = DataObject::get('Store', 'DealerGroupID=' . $_REQUEST['DealerGroupID']) ){
    $f1 = new JSONDataFormatter();
    return $f1->convertDataObjectSet($data);
    }else{
    return '{"items": []}';
    }

    } else {
    return '"items": []}';
    }

    }

  • Willr
    Avatar
    Forum Moderator
    5163 Posts

    Re: DataObject::get not working in Ajax call unless logged in as admin Link to this post

    You may need to define a canView() method on your Store object to indicate that those results can be viewed.

    public function canView($member = null) {
    return true;
    }

    164 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.