我真的不知道 Kohana 3 中的分页是如何工作的。Kohana 3 中是否有一个很好的分页示例?
// 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
这里发生的是 Pagination 类使用它的 View 的 __toString() 魔术方法来渲染显示分页所需的 html。创建对象时可以修改所有分页参数(在我们的例子中将适当的键传递给传递给factory()方法的数组)。
分页的默认键是“page”(查询字符串),您也可以修改它。分页还有一个默认配置,您可以通过将其复制到 application/config 文件夹来覆盖它。
享受使用它的乐趣:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)