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.

General Questions /

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

Model Admin - so many questions, so little documentation


Go to End
Reply


18 Posts   8193 Views

Avatar
DesignCity

38 Posts

10 March 2009 at 4:06pm

Edited: 10/03/2009 4:07pm

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

Avatar
samtihen

Community Member, 3 Posts

19 March 2009 at 4:27pm

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.

Avatar
samtihen

Community Member, 3 Posts

19 March 2009 at 4:32pm

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.

[url=https://pastee.org/fyaz9]Example Code that works in ModelAdmin[/url]

Avatar
Fuzz10

Community Member, 787 Posts

23 March 2009 at 11:29pm

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 ?

Avatar
martimiz

Forum Moderator, 1106 Posts

13 May 2009 at 11:19pm

Edited: 14/05/2009 12:43am

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

Avatar
Jedateach

Forum Moderator, 232 Posts

4 June 2009 at 5:13pm

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

Avatar
AdamJ

Community Member, 145 Posts

4 June 2009 at 5:15pm

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

Avatar
Ingo

Forum Moderator, 801 Posts

5 June 2009 at 9:15am

> 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 :)

Go to Top