Jump to:

23355 Posts in 17838 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » How to get Model Admin without Table , just to edit one Object !

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: 415 Views
  • DesignerX.com.au
    Avatar
    Community Member
    107 Posts

    How to get Model Admin without Table , just to edit one Object ! Link to this post

    Hi, I am trying to create a ModelAdmin section that edits One Object instead of having a table of Objects .
    If we look at the Settings Section/ModelAdmin then that is exactly what I want, When I click the Settings tab I get the textFields to edit the site Title & Tagline .
    How can I do that ? been looking at the SiteConfig.php & CMSSettingsController.php for some time but didnt 100% get it all ..
    Love to get some help & work out a solution that we can publish too

    Thanks

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: How to get Model Admin without Table , just to edit one Object ! Link to this post

    The easiest way of getting similar functionality I think would be to create the ModelAdmin with the DataObject.

    Ensure the permissions of the DataObject make canCreate and canDelete return false.

    Add a requireDefaultRecords function to ensure one record is always created on a dev/build (if it doesn't already exist).

    The only downside is that you need to search for and then click the record to then edit it - however I know there is a small js hack to get records to auto load... it would take much to extend that to open the record into an edit form each time.

    Not ideal GUI, but functionality - hope this helps.

  • kinglozzer
    Avatar
    Community Member
    138 Posts

    Re: How to get Model Admin without Table , just to edit one Object ! Link to this post

    I've wondered how to do this before as well. I haven't had a chance to look at it properly, but from looking at the existing classes I'd guess:

    CMSSettingsController extends LeftAndMain, not ModelAdmin, so when creating your class, try extending LeftAndMain and not ModelAdmin.

    Then I think you'll need to overwrite getEditForm() to load in your DataObject - Use CMSSettingsController as an example.

    It looks like there'll be extra stuff to work out, like getting the CMS actions to pass into the form, but it's a starting point.

    Good luck!

  • DesignerX.com.au
    Avatar
    Community Member
    107 Posts

    Re: How to get Model Admin without Table , just to edit one Object ! Link to this post

    Hi, these sound like good solutions. I will be playing around with them soon .
    If you guys have any related code, even 1/2 working please post here .
    Thanks for your input guys

    415 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.