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.

Archive /

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

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

Error saving content on Complex Field


Go to End


6 Posts   3039 Views

Avatar
fordy

Community Member, 46 Posts

17 March 2008 at 2:35am

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

}

?>

Avatar
newjamie

Community Member, 7 Posts

17 March 2008 at 11:01am

In your $tablefield declaration you have

'Fixutres',

instead of

'Fixtures',

Does changing this solve it?

Avatar
fordy

Community Member, 46 Posts

18 March 2008 at 1:59am

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

Avatar
Hayden

Core Development Team, 19 Posts

19 March 2008 at 4:48pm

Edited: 19/03/2008 4:49pm

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

Avatar
zanami.ru

Community Member, 6 Posts

28 March 2008 at 2:25pm

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!

Avatar
zanami.ru

Community Member, 6 Posts

28 March 2008 at 3:59pm

Just to answer mysleft
Looks like this does the trick

$tablefield->relationAutoSetting = true;