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:

Data Model Questions /

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

Help with basic table - managed via modelAdmin - with display limit & multiple page results

Go to End

3 Posts   1488 Views


Community Member, 219 Posts

26 August 2010 at 3:38am


fairly new to SS, but loving it so far.
working on a site with a table of products.
simple table, that can be managed via modelAdmin.

i want the products to then be listed in a table on the frontend, with 25 per page, with next, previous links etc. then add a search box that searches ONLY the table of products. each product will not have its own page though, just sit in the table with a link to email/enquire about that product.

so far, i have this:

to get to where i am, i created the following:

in mysite>code>myCatalgueAdmin.php

class MyCatalogAdmin extends ModelAdmin {

public static $managed_models = array( //since 2.3.2

static $url_segment = 'products'; // will be linked as /admin/products
static $menu_title = 'Catalogue Admin';


in mysite>code>Product.php:

class Product extends DataObject {

static $db = array(
'Title' => 'Varchar',
'PartNumber' => 'Varchar',
'SerialNumber' => 'Varchar',
'AircraftRegistration' => 'Varchar',
'Type' => 'Varchar',
'AircraftSerial' => 'Varchar',
'Quantity' => 'Varchar',
'Price' => 'Currency'

static $summary_fields = array(

static $searchable_fields = array(


in mysite>code>Page.php:

function ProductList ($limit = 25){
$list = DataObject::get('Product', '', '', '', $limit);
return $list;

then in themes>template>

<table id="ProductList" width="100%" border="0">
<th width="">Title</th>
<th width="">Part Number</th>
<th width="">Serial Number</th>
<th width="">Aircraft <br>
<th width="">Type</th>
<th width="">Aircraft <br>
<th width="">Quantity </th>
<th width="">Email us</th>
<% if ProductList %>

<% control ProductList %>
<tr height="20px">
<td>$Quantity </td>
<td><a href="$Title">Email us</a> </td>

<% end_control %>
<a href="$ProductList.NextLink">Next</a>
<a href="$ProductList.PrevLink">Previous</a>
<% end_if %>



i cant figure out the following:
A) am i even on the right track??
B) how do i get the next and previous links to work? currently they just change append the URL with ?start=25 but the list doesn't change
C) the search box searches the whole site (and seems to skip this table of products all together)

if anybody can help with this i will be eternally grateful!

thank you!!


Community Member, 271 Posts

26 August 2010 at 12:51pm


Community Member, 219 Posts

27 August 2010 at 11:37pm

thanks a lot,

i've made some advancements... the table, pagination, item limit etc are now all working fine.
but im having some problems with search.
the standard site search doesnt search the table of products... so i've been trying to create a custom search function (with the help of Uncle Cheese)

here's my catalogue.php so far:

class Catalogue extends Page {
public function ProductList ($filter = null){
if(!isset($_REQUEST['start'])) $_REQUEST['start'] = 0;
$limit = $_REQUEST['start'].",25";
return DataObject::get('Product', $filter, null, null, $limit);

public function ProductSearchForm() {
return new Form (
new FieldSet(new TextField('s','')),
new FieldSet(new FormAction('doProductSearch','Search'))

public function doProductSearch($data, $form) {
if(isset($data['s'])) {
$filter = "SomeField LIKE '%".Convert::raw2sql($data['s'])."%'";
return array (
'ProductList' => $this->ProductList($filter)


class Catalogue_Controller extends Page_Controller {

static $allowed_actions = array (



the problem is now, when i try a search it says the page does not exist, so we tried adding the allowed_actions to the controller, but now when i try and search it says "there has been an error"

can anybody else shed some light on custom search?

thanks in advance!