17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2078 Views |
-
Error saving content on Complex Field

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 );
}
}?>
-
Re: Error saving content on Complex Field

17 March 2008 at 11:01am
In your $tablefield declaration you have
'Fixutres',
instead of
'Fixtures',
Does changing this solve it?
-
Re: Error saving content on Complex Field

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
-
Re: Error saving content on Complex Field

19 March 2008 at 4:48pm Last edited: 19 March 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)
); -
Re: Error saving content on Complex Field

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!
-
Re: Error saving content on Complex Field

28 March 2008 at 3:59pm
Just to answer mysleft
Looks like this does the trick$tablefield->relationAutoSetting = true;
| 2078 Views | ||
|
Page:
1
|
Go to Top |



