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.

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   1566 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?