Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » searchcontext filter

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

Page: 1
Go to End
Author Topic: 1393 Views
  • Neven
    Avatar
    Community Member
    1 Post

    searchcontext filter Link to this post

    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!

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: searchcontext filter Link to this post

    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()

    1393 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.