我对kohana的分页工作原理感到迷茫3.在任何地方Kohana 3都有分页的好例子吗?Kohana 3分页
6
A
回答
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();
,然后在视图中,你只是做
echo $pagi; // ofc, after passing the Pagination object to view
这里会发生什么事是分页类用它查看的__toString()魔术方法来呈现,以显示分页所需的HTML。所有分页参数都可以在创建对象时修改(在我们的例子中,传递适当的键到传递给factory()方法的数组)。
分页的默认键是“page”(查询字符串),您也可以修改它。分页还有一个默认配置,您可以通过将其复制到应用程序/配置文件夹来覆盖它。
使用它:)
2
你可以在unofficial Kohana wiki找到一些体面的文档。
3
在Kohana 3.1分页不包括在内。下载模块并将其放入模块文件夹中。启用应用程序中的模块/ bootstrap.php。这是我的控制器页面。对于进一步的配置从模块复制所提供的配置文件/分页/配置/ pagination.php到的application/config/pagination.php
$per_page =2;
$page_num = $this->request->param('page', 1);
$offset = ($page_num - 1) * $per_page;
$view =View::factory('image/imagelist')->bind('page_links',$page_links)->bind('results', $results)->bind('pagination', $pagination);
// Get the total count of records in the database
$userid = Auth::instance()->get_user()->pk();
$count=ORM::factory('user_image')->where('app_userid','=',$userid)->count_all();
// Create an instance of Pagination class and set values
$pagination = Pagination::factory(array(
'total_items' => $count,
'current_page' => array('source' => 'image/imagelist', 'key' => 'page'),
'items_per_page' => $per_page,
'offset' => $offset,
'view' => 'pagination/basic'
));
// Load specific results for current page
$results = DB::select()->from('user_images')
->where('app_userid','=',$userid)
->order_by('image_id','ASC')
->limit($pagination->items_per_page)
->offset($pagination->offset)->execute();
$page_links = $pagination;
$this->template->content=$view->render();
你可能会得到错误ErrorException [注意]:未定义的属性:Request::$uri
。在分页类(模块)中。为了解决固定它
使用Request::current()->uri()
代替Request::current()->uri
相关问题
- 1. Kohana 3分页和路线问题
- 2. Kohana 3分页,如何设置最大页面链接限制?
- 3. Kohana 3.0分页程序不分页
- 4. 在Kohana 3 insert_id 3
- 5. Kohana分页和JavaScript标签
- 6. Kohana的路线和分页
- 7. Kohana 3 - 重定向到404页
- 8. Adodb和Kohana 3
- 9. Kohana 3 - 比Kohana 2更容易吗?
- 10. Kohana的3 - 从URL
- 11. Kohana 3公告板
- 12. Kohana 3 - SphinxQL配置
- 13. Kohana 3 route not matching
- 14. Kohana 3:has_many和order_by
- 15. Kohana 3 class name convention
- 16. Kohana 3 JavaScript问题
- 17. Kohana的3 - 构造
- 18. 使用kohana关系(has_many等..)与kohana分页
- 19. 在Kohana 3中获取完整网站主页的URL 3
- 20. 的Kohana 3.3 - 分页缺少行动parametr
- 21. Kohana 3.1查询计数和分页
- 22. Kohana分层路由与子页面
- 23. CakePHP 3分页
- 24. Kohana URL(分段)
- 25. 在Kohana 3制作水印3
- 26. Kohana 3中的PHP会话3
- 27. Kohana 3中的基本URL 3
- 28. 在kohana 3中实现uploadify 3
- 29. 管理Kohana 3中的bootstrap.php 3
- 30. Kohana的3.X call_user_func()错误
也ORM具有有用'count_last_query(),用于计数结果行'方法。 – biakaveron 2010-11-05 19:40:02
尽管在复杂查询时我不会太依赖这种方法:)通过这种方式,我们可以重新使用计数查询,并在计数发生前添加重置(FALSE)。 – Kemo 2010-11-05 21:28:16
酷!这很有用,谢谢! – dana 2011-03-19 13:21:46