Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » pass a variable from a different table than SiteTree DB to JSON

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

Page: 1
Go to End
Author Topic: 797 Views
  • joninjas
    Avatar
    Community Member
    32 Posts

    pass a variable from a different table than SiteTree DB to JSON Link to this post

    Hi all,

    We did a nice implementation of flash with the Silverstripe backend. We're working on it, have a look:
    http://krayersm.sites.hostmax.ch/projekte/

    Everything works well, except that we can't pass on variables from other tables, just default fields from the SiteTree like $Title, $MenuTitle, $URLSegment...

    The JSON output you can see from: http://krayersm.sites.hostmax.ch/projekt1/jsonausgabe
    The variable 'Anzahl' just shows: Anzahl":null," which is not the data existing in this field.
    Does anybody know why this variable is not being sent with JSON. We even can't access the $Ausgabe in a SS-file.

    We'd be really glad to get a feedback.

    yesmate!
    Jonas

    Attached Files
  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: pass a variable from a different table than SiteTree DB to JSON Link to this post

    You have the following code

    'Anzahl' => $this->Anzahl,
    'DeltaX' => $this->DeltaX,
    'DeltaY' => $this->DeltaY,

    $this->Field would look for the database field on ProjektPage or Page.php. Those fields aren't on ProjektPage so $this-> won't work. Your using a ComplexTableField to manage the objects - did you want to attach multiple Projekteintrag to the ProjektPage or just 1? If its just one then you need a relationship to map the object to the page

    static $has_one = array('Projekteintrag' => 'Projektangaben');

    Then your ComplexTableField needs to be changed to a HasOneComplexTableField and that code I posted first would be changed to look like

    'Anzahl' => $this->Projekteintrag()->Anzahl,
    'DeltaX' => $this->Projekteintrag()->DeltaX,
    'DeltaY' => $this->Projekteintrag()->DeltaY,

  • joninjas
    Avatar
    Community Member
    32 Posts

    Re: pass a variable from a different table than SiteTree DB to JSON Link to this post

    Hi Willr,

    Thanks a lot for your reply. I changed the files according to your suggestion. Just the 'HasOneComplexTableField' I couldn't use otherwise the fields woudn't show in the backend after filling in the form... so I left it to ComplexTableField.

    I had no errors, just the
    http://krayersm.sites.hostmax.ch/projekt1/jsonausgabe
    still shows:

    "Anzahl":null,"DeltaX":null,"DeltaY":null,

    ...where it should show the value from the DB.
    Could you imagine why?

    I attached the two changed files (attention: all the 'projektangaben' I changed to 'projektangabe').

    Thanks
    Jonas

    Attached Files
    797 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.