与Lister的分页

时间:2013-11-19 16:43:32

标签: pagination atk4

我大约2小时前开始使用Agile Toolkit,我无法解决一个问题:
我需要在博客的主页面和类别页面中添加分页,这是我的方式:

    $lister = $this->add('Lister_Paginated',null,'Posts','Posts');
    $lister->setSource('posts');
    $lister->dq->where('published = FALSE')->order('date',true);
    $lister->addPaginator(5);

模板文件

<?Posts?>
   <?rows?>
    <?row?>
    <div class="post">
      <a href="/read/<?slug?>slug<?/?>.html"><img src="/uploads/img/<?previewIMG?>empty.jpg<?/?>" width="180" height="182"/></a><br />
      <span class="postTitle"><a href="/read/<?slug?>slug<?/?>.html"><?title?>Заголовок поста<?/?></a></span>
    </div>
    <?/row?>
   <?/rows?>
   <?$paginator?> 
  <?/Posts?>

但是paginator不起作用(内容不会改变)

2 个答案:

答案 0 :(得分:0)

Lister中没有这样的方法。您应该使用此方法here并添加到项目Lister


LIB /李斯特/ Paginated.php

class Lister_Paginated extends CompleteLister {
    public $paginator;
    function addPaginator($ipp = 25, $options = null) {
        // adding ajax paginator
        if ($this->paginator) {
            return $this->paginator;
        }
        $this->paginator = $this->add('Paginator', $options);
        $this->paginator->ipp($ipp);
        return $this;
    }
    function defaultTemplate() {
        return array('view/lister/paginated');
    }
}

查看/利斯特/ paginated.html

<<?element?>ul<?/?> class="atk-lister <?$class?>" id="<?$_name?>">
<?rows?>
    <?row?>
        <<?row_element?>li<?/?> class="atk-lister-row <?$odd_even?>">
            <h3><?$name?></h3>
        </<?row_element?>li<?/?>>
    <?/row?>
    <?totals?>
    <<?row_element?>li<?/?> class="atk-lister-totals">
         Total: <?$row_count?> row<?$plural_s?>
    </<?row_element?>li<?/?>>
    <?/totals?>
<?/rows?>
<?$Content?>
<?$paginator?>     <---------------------------
</<?element?>ul<?/?>>

用法:

$lister = $this->add('Lister_Paginated');
$lister->->addPaginator();

答案 1 :(得分:0)

您使用Lister还是CompleteLister?

不要使用addPaginator,因为它已经很老了。使用$ lister-&gt; add('Paginator') - &gt; ipp(2);它适用于CompleteLister就好了。