Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Pagination

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

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

Page: 1 2
Go to End
Author Topic: 5972 Views
  • nodevice
    Avatar
    Community Member
    37 Posts

    Pagination Link to this post

    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).

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Pagination Link to this post

    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?

  • nodevice
    Avatar
    Community Member
    37 Posts

    Re: Pagination Link to this post

    yes, thast´s what im looking for

  • pouderStream
    Avatar
    Community Member
    33 Posts

    Re: Pagination Link to this post

    That would be great to know, yes.

  • Matt
    Avatar
    Core Development Team
    84 Posts

    Re: Pagination Link to this post

    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.

  • nodevice
    Avatar
    Community Member
    37 Posts

    Re: Pagination Link to this post

    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!

  • Matt
    Avatar
    Core Development Team
    84 Posts

    Re: Pagination Link to this post

    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.

  • nodevice
    Avatar
    Community Member
    37 Posts

    Re: Pagination Link to this post

    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

    5972 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.