Kohana 3分页 [英] Kohana 3 pagination

查看:89
本文介绍了Kohana 3分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的对kohana 3中的分页工作方式迷失了.在任何地方的Kohana 3中是否有很好的分页实例?

I'm really lost on how pagination works in kohana 3. Is there a good example of pagination in Kohana 3 anywhere?

推荐答案

        // Get the total count of articles
    $count = $this
        ->_profil
        ->articles
        ->count_all();

    // Create the pagination object
    $pagi = Pagination::factory(array(
        'items_per_page'    =>  4,
        'total_items'       =>  $count,
    ));

    // Find actual articles
    $articles = $this->_profil
        ->articles
        ->join_categories()
        ->order_by('id','DESC')
        ->limit($pagi->items_per_page)
        ->offset($pagi->offset)
        ->find_all();

然后在视图中,您只需

echo $pagi; // ofc, after passing the Pagination object to view

这里发生的是分页类,它使用View的__toString()魔术方法来呈现显示分页所需的html.创建对象时可以修改所有分页参数(在本例中,将适当的键传递给传递给factory()方法的数组).

What happens here is Pagination class using it's View's __toString() magic method to render html needed to display pagination. All pagination params can be modified when creating the object (passing appropriate keys to the array passed to factory() method in our case).

用于分页的默认键是页面"(查询字符串),您也可以对其进行修改.分页还具有默认配置,您可以通过将其复制到application/config文件夹来覆盖它.

Default key for pagination is "page" (query string), while you can modify that as well. Pagination also has a default config, which you can override by copying it to application/config folder.

喜欢使用它:)

这篇关于Kohana 3分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆