Kohana 3分页

Ada*_*amB 6 php pagination kohana kohana-3

我真的迷失在考纳如何在kohana 3中工作.在Kohana 3的任何地方都有一个很好的分页例子吗?

Kem*_*emo 14

        // 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();
Run Code Online (Sandbox Code Playgroud)

然后在视图中,你就是这么做的

echo $pagi; // ofc, after passing the Pagination object to view
Run Code Online (Sandbox Code Playgroud)

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

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

享受使用它:)