我正在尝试对ArticlePages的Paginated列表进行排序。 文章页面有一个'日期'字段我想用于排序。分页有效,但排序不起作用。我错过了什么?很多!
根据API / PaginatedList http://api.silverstripe.org/3.1/class-PaginatedList.html 有一个sort()方法http://api.silverstripe.org/3.1/class-SS_ListDecorator.html#_sort
ArticlePage.php
class ArticlePage extends Page {
private static $db = array(
'Place' => 'Text',
'Date' => 'Date',
);
ArticleHolder.php
class ArticleHolder_Controller extends Page_Controller {
public function PaginatedArticles(){
$paginatedItems = new PaginatedList(ArticlePage::get(), $this->request);
$paginatedItems->sort('Date DESC');
$paginatedItems->setPageLength(4);
return $paginatedItems;
}
ArticleHolder.ss
<% loop $PaginatedArticles %>
<% include ArticlePage %>
<% end_loop %>
答案 0 :(得分:2)
$ paginatedItems-&gt; sort()方法应该有效。你能检查一下你的记录是否真的有日期值,并且它们是否符合预期?
另一种方法:
PHP
$paginatedItems = new PaginatedList(ArticlePage::get()->sort("Date DESC"), $this->request);