Jump to:

2012 Posts in 1438 Topics by 621 members

Form Questions

SilverStripe Forums » Form Questions » GridField problem with custom data.

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

Page: 1
Go to End
Author Topic: 390 Views
  • T3nD4n
    Community Member
    16 Posts

    GridField problem with custom data. Link to this post

    Hi! i'm need to show custom data in a GridField, to achieve that this is the part of my code

    class Player extends DataObject {
       static $has_many = array(
          'Scores' => 'Score',
       public function getCMSFields() {
          $fields = parent::getCMSFields();

          $config = GridFieldConfig_RecordEditor::create();
                   'Points' => 'Points'

          $scores= new GridField(
                'Scores', // Field name
                'Score', // Field title
                $this->myScores(), // List of all related Scores

          $fields->addFieldToTab('Root.Main', $scores);
          return $fields;
       public function myScores(){
          $controller = Controller::curr();
          $bread = $controller->breadcrumbs();
          $match= $bread->last();
          $matcid= end(explode("/",$partido->Link));// the id of the match that this player belongs
          return Score::get("Score", "MatchID = $matcid AND PlayerID = $this->ID");

    I'm passing $this->myScores() to the gridfield and works fine, shows me the list of Scores with the filter applied in the function "myScores", I pass this function because a "Score" have a relation with another class ("Match") too, and if I pass to the gridfield $this->Scores, shows me scores that dont have to show.

    well this part is working. the problem is when I want to add a new score, when I click in the green "add Score" button, takes me to the new score screen, and when i save it, the record is saved but PlayerID is set to null in the database.

    if I change $this->myScore() for $this->Scores() in the gridfield, when I save a new Score the PlayerID is saved ok.

    Im very new in silverstripe, and any help will be apreciatted

    my version of ss is 3.0.5.

    PD: sorry for my bad english.

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.