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.

Form Questions /

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

searchcontext filter


Go to End


2 Posts   2130 Views

Avatar
Neven

Community Member, 1 Post

17 January 2010 at 2:56am

Hi, ovo je moje prvo pitanje na ovom forumu

I'm using searchcontext logic for my search form but I have problem.

Code:

static $searchable_fields = array(
'Naziv' => 'PartialMatchFilter',
'Cat' => 'PartialMatchFilter',
'Mapid' => 'ExactMatchFilter',
);

//////

function InfoResults($searchCriteria = array()) {

$request = ($this->request) ? $this->request : $this->parentController->getRequest();
if(!$searchCriteria) $searchCriteria = $request->requestVars();

$start = ($request->getVar('start')) ? (int)$request->getVar('start') : 0;
$limit = $this->stat('podataka_po_strani');

$context = singleton('Info')->getDefaultSearchContext();
$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;
}

Everything works well but How do I add a permanent filter in the results, regardless of the query such as "WHERE `Cat` NOT LIKE '%ulic%'"

Thanks for any hint!

Avatar
Ingo

Forum Moderator, 801 Posts

25 January 2010 at 12:35pm

Hm, either by prepopulating your search form (through HiddenField or default values for other formfields), or by modifying $searchCriteria in your controller code before invoking getResults()