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.

General Questions

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

DataExtension to Member ignored for changePassword?


4 Posts   663 Views


22 February 2013 at 8:37pm Community Member, 3 Posts

I need to keep SS passwords in sync with another system. So I defined a SyncedMember class in a SyncedMember.php file. I then set up my own custom changePassword:

class SyncedMember extends DataExtension {
   public function changePassword($password) {
      $valid = $this->owner->changePassword($password);

      if ($valid) {
         // do my actual logic here to update the password in my other system
      return $valid;

It's not getting called when I run through the dialog in /Security/changepassword. I have tried making the first line of the function in the extension 'garbagecall();' to see if it was a problem with the details of my code, but there's no error. The extension's changePassword isn't getting called at all.

I have several other DataObject extensions working successfully. In my _config.php I have:

Object::add_extension('Member', 'SyncedMember');

I ran dev/build and flushed before trying my changes. I am on SS 3.0. If I directly edit the changePassword definition in framework/security/Member.php it works as expected.


22 February 2013 at 9:22pm (Last edited: 22 February 2013 9:27pm), Community Member, 215 Posts

I'm afraid, you cannot overload Member->changePassword with a DataExtension. You need to subclass Member.

Object::useCustomClass("Member", "SyncedMember");

Though, this might not completely work out of the box... Object::useCustomClass ist somewhat mysterious... Maybe you need a DataExtension for Member too, which changes Member to SyncedMember via the onBeforeWrite, onAfterWrite or augmentWrite method.


22 February 2013 at 9:56pm Community Member, 3 Posts

Thanks! Did I misunderstand how data extensions are used? I thought I could customize any class's functions this way if the parent descends from Object. And even the online manual extends Member as its example for DataExtension. Is there an easy way to tell when you must subclass instead of extend?


22 February 2013 at 10:41pm Community Member, 215 Posts

With a DataExtension you can add functionality to a DataObject (only). You can add DB fields and methods, further you can augment write methods (@see $this->extend()). But you cannot replace/overload a method.

And even the online manual extends Member as its example for DataExtension.

Nope. There is a example for subclassing Member ("the least desirable way") and subclassing DataExtension.

Please read the docs carefully and then choose how to proceed. This is a sensitive matter.

If you subclassing Member, "you have to make sure that those with login-capabilities have unique email-addresses".