Ok so I know there is tons of documentation and forum questions regarding pagination so I apologize if this has been addressed somewhere and I missed it. That being said here's the problem.
I have a data object and a custom search form for looking through it. The search seems to pull the correct results but when I click on my link to view the next page it pulls results up from all over the site.
here is the dataobject:
class Comedian extends DataObject {
static $db = array (
'FirstAppeared' => 'Date',
'FirstName' => 'Varchar',
'LastName' => 'Varchar',
'Bio' => 'HTMLText',
'Video' => 'HTMLText'
);
static $has_one = array(
'Avatar' => 'Comedian_CustomImage',
);
static $default_sort = "LastName ASC";
static $searchable_fields = array(
'FirstName',
'LastName'
);
static $search_heading = "LastName";
static $search_content = "Firstname";
static $summary_fields = array(
'FirstName',
'LastName',
'Avatar.CMSThumbnail.Tag'
);
public function getCustomSearchContext() {
$fields = $this->scaffoldSearchFields(array(
'restrictFields' => array('LastName','FirstName')
));
$filters = array(
'LastName' => new PartialMatchFilter('LastName'),
'FirstName' => new PartialMatchFilter('FirstName')
);
return new SearchContext(
$this->class,
$fields,
$filters
);
}
}
class Comedian_CustomImage extends Image {
public function generateCustomImage($gd) {
return $gd -> resizeByWidth(250);
}
}
here is the controller:
class ComediansPage_Controller extends Page_Controller
{
public function ComedianSearchForm() {
$context = singleton('Comedian')->getCustomSearchContext();
$fields = $context->getSearchFields();
$form = new Form($this, "SearchForm",
$fields,
new FieldSet(
new FormAction('doComedianSearch', 'Find Comedian')
)
);
return $form;
}
public function doComedianSearch($data, $form) {
$context = singleton('Comedian')->getCustomSearchContext();
$results = $this->getComedianResults($data);
return $this->customise(array(
'ComedianResults' => $results));
}
function getComedianResults($searchCriteria = array()) {
if($searchCriteria != array()) {
$start = ($this->request->getVar('start')) ? (int)$this->request->getVar('start') : 0;
$limit = 4;
$context = singleton('Comedian')->getCustomSearchContext();
$query = $context->getQuery($searchCriteria, null, array('start'=>$start,'limit'=>$limit));
$records = $context->getResults($searchCriteria, null, array('start'=>$start,'limit'=>$limit));
if($records) {
$records->setPageLimits($start, $limit, $query->unlimitedRowCount());
}
return $records;
}
}
}
and finally the .ss template:
<% if ComedianResults.MoreThanOnePage %>
<div id="PageNumbers">
<p>
<% if ComedianResults.NotFirstPage %>
<a class="prev" href="$ComedianResults.PrevLink" title="View the previous page">Prev</a>
<% end_if %>
<span>
<% control ComedianResults.PaginationSummary(4) %>
<% if CurrentBool %>
$PageNum
<% else %>
<% if Link %>
<a href="$Link" title="View page number $PageNum">$PageNum</a>
<% else %>
…
<% end_if %>
<% end_if %>
<% end_control %>
</span>
<% if ComedianResults.NotLastPage %>
<a class="next" href="$ComedianResults.NextLink" title="View the next page">Next</a>
<% end_if %>
</p>
</div>
<% end_if %>
<% if ComedianResults %>
<p>Comedians:<br />
<% control ComedianResults %>
$Avatar.SetWidth(100) <a style="font-style:smallCaps; font-size:16px;" href="comedians/display/$LastName/$FirstName">$FirstName $LastName</a>
<% end_control %>
</p>
<% else %>
<p>Sorry, your search query did not return any results.</p>
<% end_if %>