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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

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


Go to End


2 Posts   996 Views

Avatar
CHD

Community Member, 219 Posts

26 August 2010 at 3:36am

Hi,

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:
http://www.worldaircraftsolutions.com.sg/catalogue/

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

in mysite>code>myCatalgueAdmin.php

<?php
class MyCatalogAdmin extends ModelAdmin {

public static $managed_models = array( //since 2.3.2
'Product'
);

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

}
?>

in mysite>code>Product.php:

<?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(
'Title',
'PartNumber',
'SerialNumber'
);

static $searchable_fields = array(
'Title',
'PartNumber',
'SerialNumber'
);

}
?>

in mysite>code>Page.php:

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

then in themes>template>catalogue.ss

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

<!--$ProductList.sort(Title)-->
<% control ProductList %>
<tr height="20px">
<td>$Title</td>
<td>$PartNumber</td>
<td>$SerialNumber</td>
<td>$AircraftRegistration</td>
<td>$Type</td>
<td>$AircraftSerial</td>
<td>$Quantity </td>
<td><a href="mailto:test@test.com?subject=$Title">Email us</a> </td>
</tr>

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

</table>

$SearchForm

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!!

Avatar
swaiba

Forum Moderator, 1899 Posts

31 August 2010 at 12:21am

This gives a nice overview...
http://doc.silverstripe.org/tutorial:4-site-search
This gives a way of chaning the results to add your data object (note it is not nescacarily the best way)
http://silverstripe.org/customising-the-cms/show/288544?start=0#post288644