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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Searchcontext with multiple DataObjects

Go to End

2 Posts   832 Views


Community Member, 35 Posts

2 July 2012 at 10:07pm

I am using the search context to search a DataObject within model admin. I have followed this: to get it working.

How can I get this to work with multiple DataObjects?


Community Member, 96 Posts

3 July 2012 at 10:59pm

Add this to your Page_Controller (in the Page.php):

public function results($data, $form){
$data = $_REQUEST;

$query = htmlspecialchars($data['Search'], ENT_QUOTES,'UTF-8');

$obj1 = DataObject::get("Obj1","MATCH (Title, MetaKeywords) AGAINST ('$query' IN BOOLEAN MODE)");
$obj2 = DataObject::get("Obj2","MATCH (Title, MetaKeywords) AGAINST ('$query' IN BOOLEAN MODE)");
$obj3 = DataObject::get("Obj3","MATCH (Title, MetaKeywords) AGAINST ('$query' IN BOOLEAN MODE)");

$searchresults = new DataObjectSet();

$data['Results'] = $searchresults;
} else {
$data['Results'] = '';

$data['Title'] = 'Searchresults';

return $this->customise($data)->renderWith(array('Page_results', 'Page'));

This works for the standard searchfield in Silverstripe.