I am using SS3, but I have used the documentation (http://doc.silverstripe.org/framework/en/topics/search). I got it working ofcourse, but I want to use multiple dataobjects, but I dont understand the following sentence.
In case you need multiple contexts, consider namespacing your request parameters by using FieldList->namespace() on the $fields constructor parameter.
Is there anyone, who could help me? This my current code.
public function SearchForm() {
$context = singleton('CaseItem')->getCustomSearchContext();
$fields = $context->getSearchFields();
$form = new Form($this, "SearchForm",
$fields,
new FieldList(
new FormAction('doSearch')
)
);
return $form;
}
public function doSearch($data, $form) {
$context = singleton('CaseItem')->getCustomSearchContext();
$results = $this->getResults($data);
return $this->customise(array(
'Results' => $results
))->renderWith(array('Page_results', 'Page'));
}
public function getResults($searchCriteria = array()) {
$start = ($this->request->getVar('start')) ? (int)$this->request->getVar('start') : 0;
$limit = 10;
$context = singleton('CaseItem')->getCustomSearchContext();
$query = $context->getQuery($searchCriteria, null, array('start'=>$start,'limit'=>$limit));
$records = $context->getResults($searchCriteria, null, array('start'=>$start,'limit'=>$limit));
if($records) {
$records = new PaginatedList($records, $this->request);
$records->setPageStart($start);
$records->setPageLength($limit);
}
return $records;
}