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

Single record in ModelAdmin


Go to End


5 Posts   1175 Views

Avatar
haugen

Community Member, 14 Posts

3 September 2013 at 6:37pm

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.

Avatar
swaiba

Forum Moderator, 1899 Posts

4 September 2013 at 1:17am

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

Avatar
haugen

Community Member, 14 Posts

4 September 2013 at 10:39pm

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.

Avatar
swaiba

Forum Moderator, 1899 Posts

4 September 2013 at 11:01pm

how about...

	function canAdd()		{return false;}

Avatar
haugen

Community Member, 14 Posts

9 September 2013 at 8:27pm

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

Thanks alot for quick replies, pretty awesome community.