Here's the other SS3 snippet
Page_Controller
public function SearchForm(){
$searchText = _t('SearchForm.SEARCH', 'Search this site ...');
if($this->request && $this->request->getVar('Search')) {
$searchText = $this->request->getVar('Search');
}
$fields = new FieldList(
$textField = TextField::create('Search',$searchText)
);
$validator = new RequiredFields('Search');
$actions = new FieldList(FormAction::create('doSearch','Go'));
$form = new ZZSearchForm($this,'SearchForm',$fields,$actions,$validator);
$form->disableSecurityToken()->setFormMethod('get');
return $form;
}
public $isSearched = false;
public static $classesToSearch = array('SiteTree');
public function doSearch($data, $form, $request) {
$this->isSearched = true;
$limit = 10;
$form->classesToSearch(self::$classesToSearch)->setPageLength($limit);
$tplData = array(
'PageResults' => $form->getResultsByClass('SiteTree'),
'Query' => $form->getSearchQuery(),
'Title' => _t('SearchForm.SearchResults', 'Search Results')
);
$ar = $this->extend('updateDoSearch',$tplData,$form);
if(!empty($ar)){$tplData = $ar[0];} // dirty
return $this->owner->customise($tplData)->renderWith(array('Page_results', 'Page'));
}
public function isSearched(){
return $this->isSearched;
}
project / _config.php
Page_Controller::$classesToSearch = array('SiteTree','CatItem'); // set classes to search
CatItem
public static $searchable_fields = array('Title','Model','Manufacturer'); // searchable fields
Page_ControllerExtender
public function updateDoSearch($tplData,$form){
$tplData['CatItemResults'] = $form->getResultsByClass('CatItem')->setPageLength(9); // here u can set any additional data lists for ur templates
return $tplData;
}
Then u can parse ur variables in template any way u need, here's my template for an instance:
<div id="PageContainer" class="typography">
<div id="HeaderContainer">
<h1>$Title</h1>
</div>
<% if Query %>
<div class="h2">
<%t Page.RESULTSQUERY "You searched for "{Query}"" Query=$Query %>
</div>
<% end_if %>
<div class="h3">We have found following Pages</div>
<% include PageSearch %>
<div class="h3">We have found following Items</div>
<% if CatItemResults %>
<div id="BasketItems" class="row">
<ul class="basketItems clearfix">
<% loop CatItemResults %>
<% include CatItemTeaser %>
<% end_loop %>
</ul>
<% with CatItemResults %>
<% include Pagination %>
<% end_with %>
</div>
<% else %>
<div class="h3"><%t Page.RESULTSNO "Sorry, your search query did not return any results." %></div>
<% end_if %>
</div>
Pagination.ss
<% if MoreThanOnePage %>
<div class="pagination pagination-centered">
<ul>
<li class="<% if not NotFirstPage %>disabled <% end_if %>prev">
<a href="$PrevLink">«</a>
</li>
<% loop Pages %>
<li<% if CurrentBool %> class="active"<% end_if %>>
<% if Link %>
<a href="$Link">$PageNum</a>
<% else %>
<span>...</span>
<% end_if %>
</li>
<% end_loop %>
<li class="<% if not NotLastPage %>disabled <% end_if %>next">
<a href="$NextLink">»</a>
</li>
</ul>
</div>
<% end_if %>