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

can't show DataObject entries with JSONDataFormatter


Go to End


3 Posts   2123 Views

Avatar
joninjas

Community Member, 32 Posts

17 December 2010 at 7:55am

Hi all,

This JSON data just shows up on the page when I'm logged in as admin in the same browser. Does anybody has a clue why?
Otherwise it just shows this:
http://www.depot43.ch/silverflash/flashinhalte/textfelder/textfeld1/jsonausgabe

class TextFeldPage_Controller extends Page_Controller {

public function jsonausgabe() {
$data1 = DataObject::get("TextFeldangabe","TextFeldangabe.Titel='$this->URLSegment'");
$f1 = new JSONDataFormatter();
return $f1->convertDataObjectSet($data1);
}

}

Thanks for your help
Jonas

Avatar
Sam

Administrator, 690 Posts

21 December 2010 at 5:15pm

The data formatters check canView() before including a result.

By default, canView() returns Permission::check("ADMIN")

To fix this, override canView() for your TextFeldangabe object with an appropriate function.

Avatar
joninjas

Community Member, 32 Posts

22 December 2010 at 3:22am

Thanks, really helpful!!! It works now.

Additional information of someone who implemented it this way you can find here:
http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-1-keeping-it-simple/?commentStart=10

:-)
Jonas