I am using the search context to search a DataObject within model admin. I have followed this:
http://doc.silverstripe.org/framework/en/reference/searchcontext/ to get it working.
How can I get this to work with multiple DataObjects?
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
I am using the search context to search a DataObject within model admin. I have followed this:
http://doc.silverstripe.org/framework/en/reference/searchcontext/ to get it working.
How can I get this to work with multiple DataObjects?
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();
$searchresults->merge($obj1);
$searchresults->merge($obj2);
$searchresults->merge($obj3);
if($searchresults){
$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.