Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Error saving content on Complex Field

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2232 Views
  • fordy
    Avatar
    Community Member
    46 Posts

    Error saving content on Complex Field Link to this post

    Hey there,

    I am having some problems saving content on a $has_many link. I have 2 classes Team (extends Page) and Fixture (extends DataObject). When i try to save the Team page, I get an "Error saving content" error. There is no message show or in the error logs. I am a bit stumped with this.

    Could anyone help?

    Team.php

    <?php

    class Team extends Page {
       static $db = array(
          
          'TeamDivision' => 'Text',
          'TeamManager' => 'Text',
          'TeamLeague' => 'Text'
          
       
       );
       
       static $has_many = array(
          'Fixtures' => 'Fixture'
       );

       function getCMSFields() {
       
          $fields = parent::getCMSFields();
       
          $fields->addFieldToTab( 'Root.Content.Main', new TextField('TeamManager', 'Team Manager'), 'Content');
          $fields->addFieldToTab( 'Root.Content.Main', new TextField('TeamDivision', 'Team Division'), 'TeamManager');
          $fields->addFieldToTab( 'Root.Content.Main', new TextField('TeamLeague', 'Team League'), 'TeamDivision');
          
          $tablefield = new HasManyComplexTableField(
             $this,
             'Fixutres',
             'Fixture',
             array(
                'FixtureDate' => 'Fixutre Date',
                'Opposition' => 'Opposition',
                
                'HomeOrAway' => 'Home or Away',
                'Location' => 'Location',
                'Postcode' => 'Postcode',
                'IsLeague' => 'League match'
                
             ),
             'getCMSFields_forPopup'
          );
          
          $tablefield->setAddTitle( 'A Fixture' );
          
          $fields->addFieldToTab( 'Root.Content.Fixtures', $tablefield );
          
          return $fields;
             
       }
       
    }

    class Team_Controller extends Page_Controller {
       function init() {
          
          parent::init();
          
          
       }
    }

    ?>

    and Fixture.php

    <?php

    class Fixture extends DataObject {
       
       static $db = array(
          'FixtureDate' => 'Date',
          'Opposition' => 'Text',
          'HomeOrAway' => 'Text',
          'Location' => 'HTMLText',
          'Postcode' => 'Text',
          'IsLeague' => 'Text'
          
       );
       
       static $has_one = array(
          'MyTeam' => 'Team'
       );
       
       
       function getCMSFields_forPopup() {
          
          $fields = new FieldSet();
          $fields->push( new CalendarDateField( 'FixtureDate', 'Fixture Date' ) );
          $fields->push( new TextField( 'Opposition' ) );
          
          $fields->push( new DropdownField(
                         'HomeOrAway',
                         'Home Or Away',
                         array(
                         'HOME' => 'Home',
                         'AWAY' => 'Away'
                         )));
          
          $fields->push( new DropdownField(
                         'IsLeague',
                         'League Match?',
                         array(
                         'NO' => 'No',
                         'YES' => 'Yes'
                          )));
          
          $fields->push( new TextAreaField( 'Location', 'Location of Match' ) );
          $fields->push( new TextField( 'Postcode' ) );
          
          return $fields;
       }
       
       function forTemplate() {
          $template = 'FixtureDetails';
          return $this->renderWith( $template );
       }
       
    }

    ?>

  • newjamie
    Avatar
    Community Member
    7 Posts

    Re: Error saving content on Complex Field Link to this post

    In your $tablefield declaration you have

    'Fixutres',

    instead of

    'Fixtures',

    Does changing this solve it?

  • fordy
    Avatar
    Community Member
    46 Posts

    Re: Error saving content on Complex Field Link to this post

    It worked. Thank you... I am a fool.

    Could I ask another question. Using the code above, the Fixtures shows all the fixtures irrelevant of what team page i am on.

    Do you know how I can show only the records from the relevant team they were added?

    Many thanks in advance

  • Hayden
    Avatar
    Core Development Team
    19 Posts

    Re: Error saving content on Complex Field Link to this post

    I think you will need to use the $sourceFilter argument after 'getCMSFields_forPopup' in HasManyComplexTableField::__construct:

    $tablefield = new HasManyComplexTableField(
    $this,
    'Fixtures',
    'Fixture',
    array(
    'FixtureDate' => 'Fixutre Date',
    'Opposition' => 'Opposition',

    'HomeOrAway' => 'Home or Away',
    'Location' => 'Location',
    'Postcode' => 'Postcode',
    'IsLeague' => 'League match'

    ),
    'getCMSFields_forPopup',
    "Fixture.MyTeamID = {$this->ID}" // Source filter (WHERE clause in SQL)
    );

  • zanami.ru
    Avatar
    Community Member
    6 Posts

    Re: Error saving content on Complex Field Link to this post

    A newbie question, sorry.
    I use this thread as a helpful guide, but...

    I was able to filter 'Fixtures' but I don't know how to pass MyTeamID to a "Add Fixture" popup or assign the current TeamID to a new Fixture some other way. In my case Fixture is created with empty (zero) MyTeamID.

    Help me puleeez!

  • zanami.ru
    Avatar
    Community Member
    6 Posts

    Re: Error saving content on Complex Field Link to this post

    Just to answer mysleft
    Looks like this does the trick

    $tablefield->relationAutoSetting = true;

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