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.

Data Model Questions /

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

[SOLVED] 500 Error: "Uncaught Exception: Object->__call(): the method 'parent' does not exist on...

Go to End

2 Posts   1625 Views


Community Member, 165 Posts

2 April 2012 at 8:49am

I'm having a bit of a problem with this.

Basically, I want to have a dataobject, "Trainer". Each trainer has their own page on the site. The trainers must be able to log in, so I thought to extend the Member class.

When the Trainer record is created, a Page would be created for the trainer as well. And yet, I can't get it to work. I always get

ERROR [User Error]: Uncaught Exception: Object->__call(): the method 'parent' does not exist on 'TrainerPage'
IN POST /allactive/admin/Data/Trainer/16/EditForm?action_doSave=Save
Line 724 in /var/www/allactive/sapphire/core/Object.php

Can anybody tell me what I've done wrong?

Here's the code for TrainerPage.

class TrainerPage extends SiteTree{
static $has_one = array(
"Trainer" => "Trainer"

class TrainerPage_Controller extends Page_Controller{


and Trainer:

class Trainer extends Member{

static $db = array(
"TR_LandlineNumber" => "Varchar(20)",
"TR_MobileNumber" => "Varchar(20)",
"TR_Notes" => "Text"

static $has_one = array(
"TR_Area" => "Area",
"TR_Region" => "Region"

static $has_many = array(
"Client" => "Client"

function getCMSFields() {

$sqlQuery = new SQLQuery(array("ID", "AreaDescription"), "Area");
$AreaMap = $sqlQuery->execute()->map();

$sqlQuery = new SQLQuery(array("ID", "RegionDescription"), "Region");
$RegionMap = $sqlQuery->execute()->map();

$fields = parent::getCMSFields();
$fields->RemoveFieldFromTab( 'Root.Main', "DateFormat");
$fields->RemoveFieldFromTab( 'Root.Main', "TimeFormat");
$fields->RemoveFieldFromTab( 'Root.Main', "TR_AreaID");
$fields->RemoveFieldFromTab( 'Root.Main', "TR_RegionID");
$fields->RemoveFieldFromTab( 'Root.Main', "TR_Notes");
$fields->RemoveFieldFromTab( 'Root.Main', "TR_LandlineNumber");
$fields->RemoveFieldFromTab( 'Root.Main', "TR_MobileNumber");

$fields->addFieldToTab( 'Root.Main', new TextField("TR_LandlineNumber", "Landline Number"));
$fields->addFieldToTab( 'Root.Main', new TextField("TR_MobileNumber", "Mobile Number"));
$fields->addFieldToTab( 'Root.Main', new TextareaField("TR_Notes", "Notes"));
$fields->addFieldToTab( 'Root.Main', new ListboxField("TR_RegionID", "Region", $RegionMap));
$fields->addFieldToTab( 'Root.Main', new ListboxField("TR_AreaID", "Area", $AreaMap));

return $fields;

function onBeforeWrite(){

// TODO: check if the page already exists


$newTrainerPage = new Page();
$newTrainerPage->ClassName = "TrainerPage";
$newTrainerPage->Created = time();
$newTrainerPage->LastEdited = time();
$newTrainerPage->Title = $this->Surname . " " . $this->FirstName;
$newTrainerPage->URLSegment = strtolower($this->Surname . "-" . $this->FirstName);
$newTrainerPage->ShowInMenus = 1;
$newTrainerPage->ShowInSearch = 1;
$newTrainerPage->CanEditType = "Inherit";
$newTrainerPage->CanViewType = "Inherit";
$newTrainerPage->Status = "Published";
$ID = $newTrainerPage->write();

$newTrainerPage->publish("Stage", "Live");



Community Member, 165 Posts

3 April 2012 at 3:26pm


Rather than a Page(), I should have tried to create a TrainerPage()