Hi all! Can someone point me to a tutorial or an article on how to put together a search page that returns results requiring pagination; i.e. 10 results per page. I'm having a challenge getting the pagination thing to work. I have a functioning search form, controller that performs the search, returns the results to the record set display template but I get all the matching records in $Results and not just the first 10 (as an example).
Thanks!
Greg
here is the controller function ...
class ListingResidentialSearchPage_Controller extends Page_Controller {
...
function doSubmitSearch($data, $form) {
//print_r($data);
$area = $data['Area'];
$price_from = $data['PriceFrom'];
$price_to = $data['PriceTo'];
$property_class = $data['PropertyClass'];
$bedrooms = $data['Bedrooms'];
$bathrooms = $data['Bathrooms'];
$query = "Area: $area, List Price Between $price_from and $price_to, Property Class: $property_class, Bedrooms: $bedrooms, Bathrooms: $bathrooms";
$listings = DataObject::get(
'Listing',
"Area = '$area' AND L_Price >= '$price_from' AND L_Price <= '$price_to' AND PClass = ($property_class) AND TBD $bedrooms AND FB $bathrooms",
'L_Price asc',
'',
'500'
);
$listings->setPageLength(10);
$data = array(
'Results' => $listings,
'Query' => $query,
'Title' => 'Residential Search Results'
);
return $this->customise($data)->renderWith(array('ListingResidentialSearchPage_results', 'Page'));
}
}
and here is the template ...
<div id="content_main" class="grid_9 content_main" style="padding-bottom: 10px;">
<% if Level(2) %>
<% include BreadCrumbs %>
<% end_if %>
<div class="typography">
<h2>$Title: $Results.totalSize</h2>
<p>You searched for: $Query</p>
<% if Results %>
<% control Results %>
<div class="listing_record_summary" onclick="location.href='/listings/residential/view/$MLS_Number';" style="padding: 10px; margin-bottom: 10px; border: solid 1px grey;">
<div style="width: 170px; float: left;">
<img width="150px" src="$getListingImageMain.Url"/>
</div>
<div style="width: 500px; float: left;">
<h5>$Address, $Area || $$getListPriceMoneyFmt</h5>
<p>Bedrooms: $TBD, Bathrooms: $FB || MLS® $MLS_Number</p>
<p>$getPublicRemarksSummary ...</p>
</div>
<div style="clear:both;"></div>
</div>
<% end_control %>
<% else %>
<p>Sorry, your search query did not return any results.</p>
<% end_if %>
<% if Results.MoreThanOnePage %>
<div id="PageNumbers">
<% if Results.NotLastPage %>
<a class="next" href="$Results.NextLink" title="View the next page">Next</a>
<% end_if %>
<% if Results.NotFirstPage %>
<a class="prev" href="$Results.PrevLink" title="View the previous page">Prev</a>
<% end_if %>
<span>
<% control Results.Pages %>
<% if CurrentBool %>
$PageNum
<% else %>
<a href="$Link" title="View page number $PageNum">$PageNum</a>
<% end_if %>
<% end_control %>
</span>
<p>Page $Results.CurrentPage of $Results.TotalPages</p>
</div>
<% end_if %>
</div>
</div>