17488 Posts in 4473 Topics by 1978 members
| Go to End | Next > | |
| Author | Topic: | 5570 Views |
-
Pagination

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).
-
Re: Pagination

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?
-
Re: Pagination

20 February 2007 at 3:44pm Last edited: 20 February 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-paginationIf 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. -
Re: Pagination

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!
-
Re: Pagination

21 February 2007 at 9:45am Last edited: 21 February 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.
-
Re: Pagination

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.phpuser_error(Bad class to singleton() - NewsArticles,256)
user_error at line 30 of Core.phpsingleton(NewsArticles)
singleton at line 1071 of DataObject.phpDataObject::get(NewsArticles,`ParentID` = '9',,,0,2)
get at line 25 of ArticleHolder.phpArticleHolder_Controller->NewsArticles()
NewsArticles at line ofcall_user_func_array(Array,Array)
call_user_func_array at line 200 of ViewableData.phpViewableData->obj(NewsArticles)
obj at line 7 of .cacheC..lighttpd.htdocs.mysite.templates.Layout.ArticleHolder.ssinclude(C:\WINDOWS\.cacheC..lighttpd.htdocs.mysite.templates.Layout.ArticleHolder.ss)
include at line 165 of SSViewer.phpSSViewer->process(Object)
process at line 157 of SSViewer.phpSSViewer->process(Object)
process at line 150 of Controller.phpController->defaultAction(index,Array)
defaultAction at line 122 of Controller.phpController->run(Array)
run at line 12 of ModelAsController.phpModelAsController->run(Array)
run at line 48 of Director.phpDirector->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
| 5570 Views | ||
| Go to Top | Next > |




