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.

All other Modules

Discuss all other Modules here.

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

SS3: Search multiple DataObjects


Reply

2 Posts   561 Views

Avatar
arnhoe

13 November 2012 at 6:22am Community Member, 6 Posts

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;
   }

Avatar
arnhoe

20 November 2012 at 5:54am Community Member, 6 Posts

Anyone who can help me?