Jump to:

23364 Posts in 18125 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Single record in ModelAdmin

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

Page: 1
Go to End
Author Topic: 329 Views
  • haugen
    Avatar
    Community Member
    12 Posts

    Single record in ModelAdmin Link to this post

    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.

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: Single record in ModelAdmin Link to this post

    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

  • haugen
    Avatar
    Community Member
    12 Posts

    Re: Single record in ModelAdmin Link to this post

    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.

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: Single record in ModelAdmin Link to this post

    how about...

       function canAdd()      {return false;}

  • haugen
    Avatar
    Community Member
    12 Posts

    Re: Single record in ModelAdmin Link to this post

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

    Thanks alot for quick replies, pretty awesome community.

    329 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.