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:

Customising the CMS /

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

Search pagination


Go to End


1682 Views

Avatar
Jona

Community Member, 19 Posts

19 December 2008 at 6:12pm

Hi Community,

I am working with a search function on my SS-powered Web site and am looking for a little guidance. I would like to paginate my search results. Currently, I have the following contents in m Page.php file with contents that I compiled mostly using the helpful documentation.

	function SearchForm(){
    	$searchText = isset($this->Query) ? $this->Query : 'Search';
    	
    	$searchField = new TextField('Search', '', $searchText);
    	$searchField->addExtraClass('searchbox');
    	$searchField->setTitle('searchbox');
    	$fields = new FieldSet($searchField);
    	    	
    	$actions = new FieldSet(
    	                new FormAction('results', 'Go', null, null, 'searchbut', true)
    	);
    	    	
    	return new SearchForm($this, 'SearchForm', $fields, $actions);
	}
	
   function results($data, $form){
      $data = array(
         'Results' => $form->getResults(),
         'Query' => $form->getSearchQuery(),
         'Title' => 'Search Results'
      );
	
      return $this->customise($data)->renderWith(array('Page_results', 'Page'));
   }

I have discovered a page in the documentation called "searchcontext," which mentions pagination, but it does not provide an example that extends the code above. Instead, the pagination information reflects a different way of searching. Do I need to learn how to search using the searchcontext, or can I extend the code above somehow? I have tried a few various modifications to both the SS file and the PHP file to no avail.

Thanks in advance for any insight or help,
Jona