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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

DataObject::get not working in Ajax call unless logged in as admin


Go to End


2 Posts   1295 Views

Avatar
msawebdev

Community Member, 15 Posts

5 February 2013 at 5:48pm

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": []}';
}

}

Avatar
Willr

Forum Moderator, 5523 Posts

9 February 2013 at 3:29pm

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;
}