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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

Member Database fields


Go to End


8 Posts   2671 Views

Avatar
a-tech

Community Member, 39 Posts

2 May 2007 at 7:14pm

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?

Avatar
Sean

Forum Moderator, 922 Posts

2 May 2007 at 9:12pm

Edited: 02/05/2007 9:13pm

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

Avatar
Ingo

Forum Moderator, 801 Posts

2 May 2007 at 11:53pm

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"?

Avatar
a-tech

Community Member, 39 Posts

4 May 2007 at 6:33pm

Yep, the table was created.

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

Avatar
vlad77

Community Member, 1 Post

29 June 2007 at 1:04am

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');
?>

Avatar
Ingo

Forum Moderator, 801 Posts

29 June 2007 at 9:30am

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.

Avatar
dio5

Community Member, 501 Posts

22 September 2007 at 9:14pm

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

Avatar
Sean

Forum Moderator, 922 Posts

23 September 2007 at 1:13am