I find ModelAdmin more powerful than GridField in SilverStripe. My question is when do you use GridField instead of ModelAdmin?
-
I wonder why this question not marked as off-topic... – Akam May 18 '16 at 22:26
-
3@Akam, I don't think this question is off-topic as while it could be open to opinion, it really is comparing two similar technologies on one platform. – Turnerj May 18 '16 at 22:59
-
off topic because: Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. – Akam May 18 '16 at 23:56
1 Answers
ModelAdmin, taken from the SilverStripe documentation:
ModelAdmin provides a simple way to utilize the SilverStripe Admin UI with your own data models. It can create searchables list and edit views of DataObject subclasses, and even provides import and export of your data.
It also goes on to state that ModelAdmin is powered by GridField. What you already likely know, GridField can be used directly outside of ModelAdmin easily on things like Pages or other DataObjects.
Think of ModelAdmin as a container for DataObjects, utilising GridField for viewing and navigating them. Items in ModelAdmin don't have to have a relation to a page.
Because of this, things like managing permissions to view specific DataObjects becomes easier as you can more easily control whether someone logged into the CMS can view a ModelAdmin page vs trying to hide a specific GridField on a specific Page.
Now for GridField usage outside of ModelAdmin, generally you would see this on a page in the SiteTree for linking a set of DataObjects (usually via a has_many
though can be a many_many
too) to the page itself.
One good example for using GridField on a page directly is if you wanted an image gallery on a particular page. You don't need a ModelAdmin for it because you want it linked against the page itself.
An example where you would likely want to use ModelAdmin more is something like an eCommerce site. You would store orders and display them with ModelAdmin vs navigating to a particular "Shop" page in your SiteTree to view the data.
Nothing stops you from using one method or the other to display your data, each one has its own pros and out-of-the-box features without much additional configuration.

- 4,258
- 5
- 35
- 52