5102 Posts in 1520 Topics by 1116 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1664 Views |
-
Cutom Save in CMS

28 March 2009 at 6:02am Last edited: 28 March 2009 6:03am
Hi,
I am new to Silverstripe (which is amazing btw) so sorry if this has an obvious answer
Is there a way to override the Save event in the admin CMS?
What I am trying to do is save multiple records to the database at the same time.
So I have 2 date fields, StartDate & EndDate (+ some other fields)
What I want to do is loop through the dates and add/edit entries depending on the date range. For example if I choose:
2009-03-27 - 2009-03-31
It would save 5 records to the database.
I can write the function to do this no problem, but how do I get it to be called when I click the 'Save' button?
Hope this makes sense.
Cheers
Mike
-
Re: Cutom Save in CMS

28 March 2009 at 10:35am
Hi Mike,
Classes inheriting from DataObject (which includes Page), have several "on" events, including onBeforeWrite() and onAfterWrite(), which you can override.
More details: http://doc.silverstripe.com/doku.php?id=datamodel#onbeforewrite
Hope this helps!
Ben -
Re: Cutom Save in CMS

28 March 2009 at 11:04am
Hi Ben,
Thanks for the tip, I will check them out.
I actually found an interesting function which adds a custom submit button to the CMS...
function getCMSActions() {
return new FormAction(
'bulkUpdate',
'Bulk Update'
);
}But I can't quite work out how/where I need to put the bulkUpdate function.
Any ideas?
Cheers
Mike
-
Re: Cutom Save in CMS

31 March 2009 at 8:17am
Hi Mike,
I'm going to guess that bulkUpdate would go as an action in your controller, but I'm not sure as I've not worked much with FormAction. Have you looked at how FormAction is used in the core files? You might find some clues there.
Ben
-
Re: Cutom Save in CMS

31 March 2009 at 8:26am
Hi Bn,
Thanks again for your reply
I dug a bit more and have decided to use the onBeforeSave method on the normal save button. So when a user clicks that I have a function which executes.
I will look at the FormAction some more later as it looks like maybe a better way to do it.
Cheers
Mike
| 1664 Views | ||
|
Page:
1
|
Go to Top |


