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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

many_many relation with custom member class


Reply

2 Posts   354 Views

Avatar
Mejoo

6 May 2012 at 1:46pm (Last edited: 6 May 2012 10:18pm), Community Member, 3 Posts

Hi Everyone

I want to built Reregistration system for Trips that planned in my community club. So, I created the TripHolder

<?php
/**
* Defines the TripHolder page type
*/
class TripHolder extends Page {
static $db = array(
);
static $has_one = array(
);

static $allowed_children = array('Trip');
}

class TripHolder_Controller extends Page_Controller {

}
?>

And also the Trip page:

<?php
/**
* Trip Page
*/
class Trip extends Page

{

static $db = array(
'Departure' => 'Date',
'Return' => 'Date',
'Location' => 'Text',
'Seats' => 'Int'
);

static $has_one = array(
);

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', $dateField = new DateField('Departure','Departure Date of the Trip (for example: 20/12/2010)'), 'Content');
$dateField->setConfig('showcalendar', true);
$dateField->setConfig('dateformat', 'dd/MM/YYYY');
$fields->addFieldToTab('Root.Content.Main', $dateField = new DateField('Return','Return Date of the Trip (for example: 20/12/2010)'), 'Content');

$dateField->setConfig('showcalendar', true);
$dateField->setConfig('dateformat', 'dd/MM/YYYY');

$fields->addFieldToTab('Root.Content.Main', new TextField('Location','The Trip Location'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new NumericField('Seats','The Available Seats on the Trip'), 'Content');

return $fields;
}

}

class Trip_Controller extends Page_Controller {
}

?>

And, I extended the member class:

<?php

class MyMember extends Member {
static $db = array(
"Mobile" => "Int",
"Institute" => "Text",
"City" => "Text",
"Institute" => "Text",
);

}

?>

So, My question is how can I make the many_many relation between MyMember class and Trip page and then member can register in a Trip.

Avatar
Mejoo

7 May 2012 at 6:56pm Community Member, 3 Posts

Is it wrong way to have relation between page and member class?

I want only member can register for a trip.

Please let me know, if you didn't get my question.