21298 Posts in 5735 Topics by 2603 members
| Go to End | Next > | |
| Author | Topic: | 796 Views |
-
Error When Creating page with DataObject

20 July 2011 at 1:18am
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.phpSource
======
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.phpHasManyComplexTableField->__construct(SpeakersPage,MySpeakers,Speakers,Array,getCMSFields_forPopup)
line 29 of SpeakersPage.phpSpeakersPage->getCMSFields(CMSMain)
line 441 of CMSMain.phpCMSMain->getEditForm(17)
line 1039 of LeftAndMain.phpLeftAndMain->EditForm()
line 389 of LeftAndMain.phpLeftAndMain->getitem(SS_HTTPRequest)
line 193 of Controller.phpController->handleAction(SS_HTTPRequest)
line 143 of RequestHandler.phpRequestHandler->handleRequest(SS_HTTPRequest)
line 147 of Controller.phpController->handleRequest(SS_HTTPRequest)
line 282 of Director.phpDirector::handleRequest(SS_HTTPRequest,Session)
line 125 of Director.phpDirector::direct(/admin/getitem)
line 127 of main.php</ul>
Any help would be appreciated!
-
Re: Error When Creating page with DataObject

20 July 2011 at 1:24am
Hey, I'm sorta new to SS, but I don't think DataObjects have a Controller, only Pages. Maybe that will get you started.
-
Re: Error When Creating page with DataObject

20 July 2011 at 1:29am
Thanks tv. I deleted the controller but it still getting the same error. Looks like the important point in the error message is "Can't find a has_one relationship from 'Speakers' to 'SpeakersPage'"
Looks ok to me though. Am I missing something fundamental?
-
Re: Error When Creating page with DataObject

20 July 2011 at 2:11am
OK. I think I'm on the right track here. What I need is to be able to add loads of Speakers to the Speakers Page. So Thats why I had the 'HasManyComplexTableField'
I realise now that the corresponding code in the speakersPage can't be
public static $has_one = array(
'MySpeakers' => 'Speakers',
);I tried:
public static $has_many = array(
'MySpeakers' => 'Speakers',
);But I still got an error? Little help?
-
Re: Error When Creating page with DataObject

20 July 2011 at 2:14am
Do you need to create a has_many relationship on Speakers? Or maybe reverse the relationship and have the has_one relationship to SpeakersPage on Speakers, so each Speaker has one SpeakerPage? Just a thought...
-
Re: Error When Creating page with DataObject

20 July 2011 at 2:15am
You need to reciprocate the relationship with a has_many on the Page. so...
Speakers has_one SpeakersPage
SpeakersPage has_many Speakers(and the controller is a very valid part of a dataobject)
-
Re: Error When Creating page with DataObject

20 July 2011 at 2:28am
Great thanks swabia. Sorry for you hasving to spoon feed me here but I tried it but I wasn't exactly sure of the syntax to refer to the speakers page in the has_one function "Speakers has_one SpeakersPage"
I tried in Speakers dataobject:
public static $has_one = array(
'MySpeakers' => 'Speakers',
);But didn't work. Thanks, appreciate the help.
-
Re: Error When Creating page with DataObject

20 July 2011 at 2:35am
This might help...
http://doc.silverstripe.org/sapphire/en/topics/datamodel
| 796 Views | ||
| Go to Top | Next > |



