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.

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

Get member by email address


Go to End


6 Posts   2153 Views

Avatar
DeklinKelly

Community Member, 197 Posts

26 August 2010 at 11:51am

I can get the current member like this:

$member = Member::currentUser();

How can I get a member by email address? This does NOT work:

$member = Member::GetUserByEmail('user@example.com');

Avatar
Martijn

Community Member, 271 Posts

26 August 2010 at 12:43pm

What about:

$m = DataObject::get_one('Member',"Email ='".$someEmailAddress."'");

Avatar
Willr

Forum Moderator, 5523 Posts

26 August 2010 at 12:51pm

Also better make sure $someEmailAddress is SQL safe as well as SS won't do this magically for you. If $someEmailAddress is a user input (like a form) you should do $someEmailAddress = Convert::raw2sql($someEmailAddress); before the dataobject get line.

Avatar
Martijn

Community Member, 271 Posts

26 August 2010 at 12:55pm

True, didn't thought of a userinput case.

Avatar
DeklinKelly

Community Member, 197 Posts

26 August 2010 at 1:50pm

Edited: 26/08/2010 1:55pm

Thanks. But I can't seem to use this the same way I use Member::

	$member = DataObject::get_one("Member",  "`Email` = 'xyz@example.com'");
	$member->CustomField = 'Hello';
	$member->write();

I am trying to change the value of CustomField to "Hello".

Avatar
Willr

Forum Moderator, 5523 Posts

26 August 2010 at 9:20pm

That is the correct way, write() should save it to the database. Does it not update the member table? How have you added that CustomField to the database (eg via a decorator?)