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

Save the member on editing a dataobject


Reply

3 Posts   400 Views

Avatar
Pipifix

1 March 2012 at 3:24am (Last edited: 1 March 2012 3:34am), Community Member, 54 Posts

Hi and Hello.

I've got a dataobject (projects) on a webpage. And there are a bunch of editors allowed to edit this dataobjects. My client want to see, which single dataobject item is edited by which editor (currentMember). So what i need is a startingpoint (or a simple tutorial) to get this problem solved.
It is neccesary to use a hook like onBeforeWrite()? Is there something like "lasteditedby"?

I guess its a simple task but i dont got a clue where to start. Thanks a lot, Pipifix

Avatar
danzzz

1 March 2012 at 6:39am Community Member, 175 Posts

hi

you can add a new field to the dataobject, for example "lasteditby"

and then set a value for it with onBeforeWrite()

function onBeforeWrite() {
   
if( $member = Member::currentUser() ) {
$this->lasteditby = $member->ID;
}
   
parent::onBeforeWrite();

}

dont tested this, but should point to right direction...

Avatar
Pipifix

1 March 2012 at 10:59pm Community Member, 54 Posts

Hi danzzz

Thanks for your response. I'll give it a try.
Pipifix