21489 Posts in 5783 Topics by 2621 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1470 Views |
-
ModelAdmin search customization

26 June 2009 at 11:08am
If I have a managed model that I want to restrict which of the DataObjects in the model can be searched for. For example I have a DataObject Student that has_one school so that some of the students have school A and some have school B. I want the ModelAdmin that is managing Students to only be able to search for students that are in School A and not School B. I would think that I could have a hidden field in the SearchForm that has the School A statically defined. I don't know how to accomplish. I want the search to work as if the person searching has put School A in the School search form but I don't actually want the person to see the form or be able to put anything in it.
I hope this makes sense.
-
Re: ModelAdmin search customization

10 July 2009 at 12:05pm Last edited: 10 July 2009 12:05pm
On the student dataobject there are a lot of parameters that might help to include. I'm not sure if it'll solve the issue but try adding
static $searchable_fields = array(
'school '
);static $defaults = array(
"school " => 'A'
);And then I think you'll need to over write the modeladmin search form with $this->fields->removeByName('school ');
I'm not that familiar with SilverStripe, let alone ModelAdmin, so this is guessing form what I've read so far
-
Re: ModelAdmin search customization

28 July 2010 at 8:22pm
I just tried to override SearchForm like this:
class MyAdmin extends ModelAdmin{
function SearchForm() {
die("yyyyyy");
$form = parent::SearchForm();
}}
But MyAdmin ran as normal. This seems very strange behaviour to me.
-
Re: ModelAdmin search customization

29 July 2010 at 12:49am Last edited: 29 July 2010 12:54am
shouldn't that be in the overridden ModelAdmin_CollectionController instead of the ModelAdmin class Nicolaas?
I have overridden the form myself, but I am just clueless on how the SearchContext stuff works. I wish it were as simple as the regular site search as that allows you to play with a DataObjectSet to add/remove as you wish... but I have no idea how to get passed the...
$context = singleton($this->modelClass)->getDefaultSearchContext();
...part. is there someone that could shed some light on this please? I have check the documentation and read the source, but the lights haven't come on yet!
Barry
-
Re: ModelAdmin search customization

29 July 2010 at 12:54am
probably yes, because it sure did not work ....
But since then I have shifted my attention to DataObject::scaffoldSearchFields and this seems to be very useful.
Cheers
Nicolaas
| 1470 Views | ||
|
Page:
1
|
Go to Top |



