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.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Pagination


Go to End
Reply


15 Posts   6085 Views

Avatar
nodevice

Community Member, 37 Posts

17 February 2007 at 1:40pm

Hi everyone, im working in my first Silverstripe site, by the way its great!!!!

I would like to know how to paginate the news in a news page (like the one from the tutorials).

Avatar
Sean

Forum Moderator, 922 Posts

17 February 2007 at 5:59pm

Are you after something like 5 articles per page, then links to more pages of articles at the bottom, with a back and next button?

Avatar
nodevice

Community Member, 37 Posts

19 February 2007 at 7:28am

yes, thast´s what im looking for

Avatar
pouderStream

Community Member, 33 Posts

20 February 2007 at 3:10am

That would be great to know, yes.

Avatar
Matt

Core Development Team, 84 Posts

20 February 2007 at 3:44pm

Edited: 20/02/2007 3:45pm

Andrew's computer, which all the tutorial files are on, has decided to kick the bucket this week, so this is going to come mostly from memory :)

I've created a temporary wiki page for it here:
http://doc.silverstripe.com/doku.php?id=temp-howto-pagination

If any of it doesn't work, or you don't understand it, then post back to this thread and I'll re-clarify.

Hopefully sometime next week either Andrew or I will get time to implement this into the second tutorial - or it may be broken out into a new 'howto' section for the Wiki.

HTH,
Matt.

Avatar
nodevice

Community Member, 37 Posts

21 February 2007 at 8:16am

Thanks Matt!!, but i'm having some troubles with the implementation.

i'm getting this message when i rebuild the database:

-Building Database

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\lighttpd\htdocs\mysite\code\ArticleHolder.php on line 32

-Here's my ArticleHolder_Controller class on the ArticleHolder.php file:

class ArticleHolder_Controller extends Page_Controller {
   function init() {
      RSSFeed::linkToFeed($this->Link() . "rss");   
      parent::init();
   }
   
   function rss() {
      $rss = new RSSFeed($this->Children(), $this->Link(), "The coolest news around");
      $rss->outputToBrowser();
   }
   function NewsArticles() {
       $doSet = DataObject::get(
         $callerClass = "NewsArticle",
         $filter = "`ParentID` = '".$this->ID."'",
         $sort = "",
         $join = "",
         $limit = "$_GET['start'],2"
       );
       return $doSet ? $doSet : false;
   }
}

Thank's for your help!

Avatar
Matt

Core Development Team, 84 Posts

21 February 2007 at 9:45am

Edited: 21/02/2007 9:53am

I'll update the Wiki page as well, but you should put curly braces around $_GET['start'] - so that line now looks like $limit = "{$_GET['start']},2"

And to fix the next bug that you'll likely have, you'll need to add this line before you call $doSet = ...:
if(!is_numeric($_GET['start']) || $_GET['start'] < 1) $_GET['start'] = 0;

Otherwise, until $_GET['start'] is created (when you click the next link for example), you'll confuse MySQL.

So your function should now look like this:
function NewsArticles() {
if(!is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
$doSet = DataObject::get(
$callerClass = "NewsArticle",
$filter = "`ParentID` = '".$this->ID."'",
$sort = "",
$join = "",
$limit = "{$_GET['start']},2"
);
return $doSet ? $doSet : false;
}

PS. This will teach me not to just post the code after Sam gives it a once-over ;)

edit: I just implemented the code on a website I'm working on and noticed a couple of bugs with the previous and next links. I've fixed them on the Wiki page, so please grab the template HTML again.

Avatar
nodevice

Community Member, 37 Posts

21 February 2007 at 10:47am

Hi again, Matt

made the changes and now i dont get the error when i flush the database.

But...
When i replace:
<% control Children %>
with
<% control NewsArticles %>

and i flush with http://localhost:3000/home/?flush=1
i get this error:

FATAL ERROR: Bad class to singleton() - NewsArticles
At line 30 in C:\lighttpd\htdocs\sapphire\core\Core.php

user_error(Bad class to singleton() - NewsArticles,256)
user_error at line 30 of Core.php

singleton(NewsArticles)
singleton at line 1071 of DataObject.php

DataObject::get(NewsArticles,`ParentID` = '9',,,0,2)
get at line 25 of ArticleHolder.php

ArticleHolder_Controller->NewsArticles()
NewsArticles at line of

call_user_func_array(Array,Array)
call_user_func_array at line 200 of ViewableData.php

ViewableData->obj(NewsArticles)
obj at line 7 of .cacheC..lighttpd.htdocs.mysite.templates.Layout.ArticleHolder.ss

include(C:\WINDOWS\.cacheC..lighttpd.htdocs.mysite.templates.Layout.ArticleHolder.ss)
include at line 165 of SSViewer.php

SSViewer->process(Object)
process at line 157 of SSViewer.php

SSViewer->process(Object)
process at line 150 of Controller.php

Controller->defaultAction(index,Array)
defaultAction at line 122 of Controller.php

Controller->run(Array)
run at line 12 of ModelAsController.php

ModelAsController->run(Array)
run at line 48 of Director.php

Director->direct(/home/)
direct at line 90 of main.php
Context
Debug (Debug::showError() in line 135 < span style="font-weight:normal">of Debug.php)

* className =

NewsArticles

* _SINGLETONS =
o SiteTree =
Database record: SiteTree
+ ID :

0

o Member =
Database record: Member
+ ID :

0

o Group =
Database record: Group
+ ID :

0

o Group_Unsecure =
Database record: Group_Unsecure
+ ID :

0

Go to Top