Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Member Database fields

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2231 Views
  • a-tech
    Avatar
    Community Member
    39 Posts

    Member Database fields Link to this post

    Ive made this file BassdropMember.php

    <?
    class BassdropMember extends Member {
       static $db = array(
          "Birthday" => "Date",
       );
       
       function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->Push(new DateField("Birthday", "Birthday"));
          return $fields;
       }
    }
    ?>

    The cms field shows up in the admin form, but theres no field in the database for birthday. I have done a flush and Im sure it said building the date field.

    The end result is I put a date in for the members birthday, and it doesnt save....

    Have I got it all wrong?

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Member Database fields Link to this post

    Normally we'd do it this way, rather than just a push of the new object...

    function getCMSFields() {
       return new FieldSet(
          new DateField("Birthday", "Birthday")
       );
    }

    Try doing it this way - unsure if this will affect anything but it's worth a shot.

    Cheers,
    Sean

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Member Database fields Link to this post

    the security-admin doesn't auto-detect different members at the moment, please use this code in _config.php to globally switch to your custom implementation:
    Object::useCustomClass('Member','BassdropMember');

    if that doesnt help: can you check that the table "BassdropMember" was properly created in your database, with a field "Birthday"?

  • a-tech
    Avatar
    Community Member
    39 Posts

    Re: Member Database fields Link to this post

    Yep, the table was created.

    Cheers, I'm catching up with sam tomorrow, and will absorb his omnipotence

  • vlad77
    Avatar
    Community Member
    1 Post

    Re: Member Database fields Link to this post

    I've tried to add new fields in Member as described above, but stucked with the problem - newly created users belongs to class Member and so doesn't have new fields in user editing form.
    I've resolved this problem by editing MemberTableField.php in cms/code.
    (version 2.0.DailyBuild.2007-06-27 and 2.0.1)

    in function MemberTableField->addtogroup
    replace
    $className = $this->stat('data_class');
    with
    $className = Object::getCustomClass($this->stat('data_class'));

    May be this a bug?

    test example:

    mysite/code/SideMember.php
    <?php
    class SideMember extends Member {
       static $db = array(
       "PriceLevel" => "Int",
       );
       
       function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->Push(
             new NumericField("PriceLevel", "PriceLevel")
          );
          return $fields;
       }
    }
    ?>

    mysite/_config.php
    <?
    global $project;
    $project = 'mysite';
    include(dirname(__FILE__).'/_config_db.php');

    Object::useCustomClass('Member','SideMember');
    ?>

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Member Database fields Link to this post

    this is indeed a bug, which is already fixed in some of our internal project-branches (still to be merged). we're approaching the whole thing a bit different now, "decorating" basic members with new stuff rather than subclassing.
    until this functionality makes it into stable, your change should be sufficient.

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Member Database fields Link to this post

    Any hints/doku of your approach to this 'decorating'?

  • Sean
    Avatar
    Forum Moderator
    921 Posts
    2231 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.