Jump to:

22997 Posts in 11853 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » many_many relation with custom member class

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

Page: 1
Go to End
Author Topic: 286 Views
  • Mejoo
    Avatar
    Community Member
    3 Posts

    many_many relation with custom member class Link to this post

    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.

  • Mejoo
    Avatar
    Community Member
    3 Posts

    Re: many_many relation with custom member class Link to this post

    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.

    286 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.