Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » Model Admin - so many questions, so little documentation

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 2 3
Go to End
Author Topic: 7850 Views
  • DesignCity
    Avatar
    38 Posts

    Model Admin - so many questions, so little documentation Link to this post

    Hi all,

    Okay, so I'm currently working with Model Admin for the first time and finding resources for it a little thin on the ground. I have some questions I'm hoping can be answered by the community:

    1. Is there a way to dynamically change the allowed actions for the ModelAdmin on a per-class basis? I'm assuming it is done with $allowed_actions, however I've not been able to actually accomplish this after trying what seems like every conceivable option.

    2. When Importing, is it possible to import data in relation to a FileIFrameField? Ie, upload the files first, then import the DO with a relationship to the file?

    3. When using the "Select result columns..." function, if you select none and try to search, you get an error as follows:

    Warning: "array_fill() [function.array-fill]: Number of elements must be positive" at line 624 of F:\sitename\cms\code\ModelAdmin.php

    Given that there is a physical option to select none of the columns to show, there should be a nicer error message (or even a popup stopping the search before it happens).

    4. Is there a way to sort the search results in the TableListField or to have it appear on opening the page?

    That should do for now... ;) Anyone got any advice?

    - DesignCity

  • samtihen
    Avatar
    Community Member
    3 Posts

    Re: Model Admin - so many questions, so little documentation Link to this post

    I'd like to put in a request for more information on how to automatically load an unconstrained search result when a ModelAdmin tab opens as well.

  • samtihen
    Avatar
    Community Member
    3 Posts

    Re: Model Admin - so many questions, so little documentation Link to this post

    And, while I'm not sure this fits here exactly, I have a little example to share about how to create a many_many relationship that has additional metadata in Silverstripe as well.

    In the example, we have Teachers and Students. A teacher can have multiple students, and a student can have multiple teachers. This would normal just be a many_many relationship. However, in this case, we have additional data we would like to store about the relationship - a grade. This no longer fits the Silverstripe model, so you have to make your own relationship table.

    Example Code that works in ModelAdmin

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: Model Admin - so many questions, so little documentation Link to this post

    Bumping this thread...

    1> Is there a way to automatically load a search result when the modeladmin is opened ?

    2> How does sorting work in the ModelAdmin ?

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: Model Admin - so many questions, so little documentation Link to this post

    Reviving...

    a. Seems that in version 2.3.2 beta $managed_objects now needs to be public.

    b. The bug where you can fysically select 'none' for searchfields is not repaired in 2.3.2. Suggestion: [EDITED] use 'ID' as a default? Or refuse to search?

    c. When adding/editing a record in the secundary tab (category in the product/category example) the complete cms is reloaded, thereby reverting the tabset to its default state (product) where the right screen still shows the category. - This means you have to be very alert when you want to add/edit again, or you end up editing the wrong dataobject...

    d. I regularly get some weird effect where after edit/save a search will now show a wrongly formatted page: sometimes it's just the right screen, sometimes the tablefield is replaced by flat text... (FF3.1 XP). I guess this is some javascript deficiency in my browser, but thougt to mention anyway...

  • Jedateach
    Avatar
    Forum Moderator
    227 Posts

    Re: Model Admin - so many questions, so little documentation Link to this post

    I too would like to know how to show a default result set, rather than needing to press 'search'.

  • AdamJ
    Avatar
    Community Member
    145 Posts

    Re: Model Admin - so many questions, so little documentation Link to this post

    Bump: I'd love to see some answers to some of these questions, especially changing the way that things work/display by default.

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Model Admin - so many questions, so little documentation Link to this post

    > 1. Is there a way to dynamically change the allowed actions for the ModelAdmin on a per-class basis? I'm assuming it is done with $allowed_actions

    No there isn't. Whats the use case?

    > 2. When Importing, is it possible to import data in relation to a FileIFrameField? Ie, upload the files first, then import the DO with a relationship to the file?

    I'd suggest you put the files into /assets, run Filesystem::sync() to ensure they're all File objects in your database. Then note the file paths in your CSV data, and cross match them in a custom method in a subclassed CSVBulkLoader. You can assign custom loaders in ModelAdmin::$model_importers.

    > 3. When using the "Select result columns..." function, if you select none and try to search, you get an error as follows:

    True, fixed in trunk (r78425)

    > Is there a way to sort the search results in the TableListField or to have it appear on opening the page?

    It uses DataObject::$default_sort. You can overload ModelAdmin->getResultsTable() and ModelAdmin->getCustomQuery() for any custom sorting.

    > I'd like to put in a request for more information on how to automatically load an unconstrained search result when a ModelAdmin tab opens as well.

    http://open.silverstripe.com/ticket/3693
    Patches welcome

    7850 Views
Page: 1 2 3
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.