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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

[solved] getCustomSearchContext not working


Go to End


1234 Views

Avatar
thomas.paulson

Community Member, 107 Posts

7 June 2014 at 7:04pm

Edited: 20/06/2014 4:08am

I create the Album Dataobject, ModelAdmin as below, to manage them in cms,

In search filter, only Name field is visible, i want to show Author also , so override the getCustomSearchContext function,

But it does seems to be not working,
,

<?php
class Album extends DataObject{
//db
private static $db = array(
'Name' => 'Varchar(200)',
'Author' => 'Varchar(200)',
);

private static $has_many = array(
'Genres'=>'Genre'
);

public function getCustomSearchContext() {
$fields = $this->scaffoldSearchFields(array(
'restrictFields' => array()
));
$filters = array(
'Author' => new PartialMatchFilter('Author'),
'Author' => new PartialMatchFilter('Author')
);
return new SearchContext(
$this->class,
$fields,
$filters
);
}

}

I know we can use, $searchable_fields but I don't want to use them. because i want to customize form fields in the search form.

solution
http://stackoverflow.com/questions/24094788/overriding-getcustomsearchcontext-is-not-working-in-silverstripe

thanks to http://www.3dgoo.com/