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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

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

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

many_many relation with custom member class


Go to End


2 Posts   655 Views

Avatar
Mejoo

Community Member, 3 Posts

6 May 2012 at 1:46pm

Edited: 06/05/2012 10:18pm

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

Community Member, 3 Posts

7 May 2012 at 6:56pm

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.