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

Single record in ModelAdmin


5 Posts   365 Views


3 September 2013 at 6:37pm Community Member, 12 Posts

Hey guys. I've been using ModelAdmin for most of my modules, and it have worked out great until now since all of my modules worked with lists/multiple records.

Now I kind of need to let admins set some settings backend, and therefor I don't need a list/multiple records. I just need a single record. I want to do exactly the same as the "Settings" tab backend in Silverstripe looks like.

How can I do this? I was wondering if there was some other approach than using ModelAdmin, or if I have to modify it to get what I want.

Thanks guys.


4 September 2013 at 1:17am Forum Moderator, 1796 Posts

Hi haugen,

Where I've done this in the past I've restricted permissions so the the record cannot be created or deleted.
Also reduce the search for (so people don't think of it like other records).
Using requireDefaultRecords to create one on dev/build if it doesn't exist.

My model admin auto searches so the only issue it that they still need to click on the record to edit it.

Hope this helps


4 September 2013 at 10:39pm Community Member, 12 Posts

Thanks, this works.

Only thing is that

function canCreate() {
    return false;

Didn't work as expected. They're still able to add new records. canDelete worked as expected.


4 September 2013 at 11:01pm Forum Moderator, 1796 Posts

how about...

   function canAdd()      {return false;}


9 September 2013 at 8:27pm Community Member, 12 Posts

Excellent. Amazing I didn't even try it before asking ;)

Thanks alot for quick replies, pretty awesome community.