Hi.
Small problem i was hoping you guys could help.
I am creating a page that lists the speakers of a specific event. I created a dataobject to hold the speakers here:
mysite/code/Speakers.php
<?php
class Speakers extends DataObject {
static $db = array(
'FirstName' => 'Text',
'LastName' => 'Text',
'Position' => 'Text',
'Company' => 'Text',
);
public static $has_one = array(
'SpeakerImage' => 'Image',
);
function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push( new TextField( 'FirstName', 'First Name' ) );
$fields->push( new TextField( 'LastName' ) );
$fields->push( new TextField( 'Position' ) );
$fields->push( new TextField( 'Company' ) );
$fields->push( new ImageField('SpeakerImage') );
return $fields;
}
}
class Speakers_Controller extends ContentController {
public static $allowed_actions = array (
);
public function init() {
parent::init();
}
}
And I want to manage the Speakers for the event here:
themes/templates/SpeakersPage.php
<?php
class SpeakersPage extends SiteTree {
public static $db = array(
'RightContent' => 'HTMLText',
);
public static $has_one = array(
'MySpeakers' => 'Speakers',
);
function getCMSFields() {
$fields = parent::getCMSFields();
$tablefield = new HasManyComplexTableField(
$this,
'MySpeakers',
'Speakers',
array(
'FirstName' => 'First Name',
'LastName' => 'Family Name',
'Position' => 'Position',
'Company' => 'Company',
'SpeakerImage' => 'Speaker Image',
),
'getCMSFields_forPopup'
);
$tablefield->setParentClass('Speakers');
$fields->addFieldToTab( 'Root.Content.Speakers', $tablefield );
$fields->addFieldToTab("Root.Content.Main", new HtmlEditorField('RightContent', 'Right Content'));
return $fields;
}
}
class SpeakersPage_Controller extends ContentController {
public static $allowed_actions = array (
);
public function init() {
parent::init();
Requirements::themedCSS('reset');
Requirements::themedCSS('960');
Requirements::themedCSS('layout');
Requirements::themedCSS('typography');
Requirements::themedCSS('form');
Requirements::javascript("js/jquery-1.6.1.min.js");
Requirements::javascript("js/jquery.nivo.slider.pack.js");
Requirements::javascript("js/slideshow.js");
}
}
I get the following error when Creating the page in Dev mode:
<br />
<b>Notice</b>: Debug::log_error_if_necessary() and Debug::log_errors_to() are deprecated. Please use SS_Log instead.
See the class documentation in SS_Log.php for more information. in <b>/var/www/vhosts/oilcouncil.com/httpdocs/event/sapphire/dev/Debug.php</b> on line <b>486</b><br />
ERROR [User Warning]: Can't find a has_one relationship from 'Speakers' to 'SpeakersPage'
IN POST /event/admin/getitem?ID=17&ajax=1
Line 56 in /var/www/vhosts/oilcouncil.com/httpdocs/event/sapphire/forms/HasManyComplexTableField.php
Source
======
47: protected $relationAutoSetting = false;
48:
49: function __construct($controller, $name, $sourceClass, $fieldList = null, $detailFormFields = null,
$sourceFilter = "", $sourceSort = "", $sourceJoin = "") {
50: parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields,
$sourceFilter, $sourceSort, $sourceJoin);
51:
52: $this->Markable = true;
53:
54: if($controllerClass = $this->controllerClass()) {
55: $this->joinField = $this->getParentIdName($controllerClass, $this->sourceClass);
* 56: if(!$this->joinField) user_error("Can't find a has_one relationship from '$this->sourceClass' to
'$controllerClass'", E_USER_WARNING);
57: } else {
58: user_error("Can't figure out the data class of $controller", E_USER_WARNING);
59: }
60:
61: }
62:
Trace
=====
<ul>user_error(Can't find a has_one relationship from 'Speakers' to 'SpeakersPage',512)
line 56 of HasManyComplexTableField.php
HasManyComplexTableField->__construct(SpeakersPage,MySpeakers,Speakers,Array,getCMSFields_forPopup)
line 29 of SpeakersPage.php
SpeakersPage->getCMSFields(CMSMain)
line 441 of CMSMain.php
CMSMain->getEditForm(17)
line 1039 of LeftAndMain.php
LeftAndMain->EditForm()
line 389 of LeftAndMain.php
LeftAndMain->getitem(SS_HTTPRequest)
line 193 of Controller.php
Controller->handleAction(SS_HTTPRequest)
line 143 of RequestHandler.php
RequestHandler->handleRequest(SS_HTTPRequest)
line 147 of Controller.php
Controller->handleRequest(SS_HTTPRequest)
line 282 of Director.php
Director::handleRequest(SS_HTTPRequest,Session)
line 125 of Director.php
Director::direct(/admin/getitem)
line 127 of main.php
</ul>
Any help would be appreciated!