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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

All other Modules /

Discuss all other Modules here.

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

SS3: Search multiple DataObjects


Go to End


2 Posts   1113 Views

Avatar
arnhoe

Community Member, 6 Posts

13 November 2012 at 6:22am

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

Community Member, 6 Posts

20 November 2012 at 5:54am

Anyone who can help me?