HI
First you define a getCustomSearchContext method inside your DataObject Class like this
function getCustomSearchContext() {
$fields = $this->scaffoldSearchFields(array (
'restrictFields' => array (
'Description' => 'Description',
'Approval_Status'=>'Approval_Status'
)
));
$filters = array (
'Description' => new PartialMatchFilter('Description'),
'Approval_Status' => new ExactMatchFilter('Approval_Status')
);
return new SearchContext($this->class, $fields, $filters);
Create you form in mysite code
<?php
class YourSearchForm extends Form {
function __construct($controller, $name) {
$context = singleton('YourDataObject')->getCustomSearchContext();
$fields = $context->getSearchFields();
$actions = new FieldSet(new FormAction('doSearch', 'Search'));
//$form = new Form($this, "SearchForm",$fields, $actions);
parent :: __construct($controller, $name, $fields, $actions);
}
public function doSearch($data, $form) {
$context = singleton('Classified')->getCustomSearchContext();
$results = $context->getResults($data);
return $this->customise(array(
'Results' => $results
))->renderWith(array('Classified_results', 'Page'));
}
function getResults($searchCriteria = array()) {
$start = ($this->request->getVar('start')) ? (int)$this->request->getVar('start') : 0;
$limit = 20;
$context = singleton('Classified')->getCustomSearchContext();
$query = $context->getQuery($searchCriteria, null, array('start'=>$start,'limit'=>$limit));
$records = $context->getResults($searchCriteria, null, array('start'=>$start,'limit'=>$limit));
if($records) {
$records->setPageLimits($start, $limit, $query->unlimitedRowCount());
}
return $records;
}
}
?>
then Initiate your Form either at Page_Controller or HomePage_Controler like this
function YourSearchForm () {
return new YourSearchForm ($this, 'YourSearchForm ');
}
HomePage.ss
$YourSearchForm