如何在MVC中实现kohana分页?

时间:2021-05-16 14:30:52

that's it. How do I implement the Kohana pagination library in MVC way? which code should go to the model? to the controller? to the view? I have seen tons of examples but none of them are implemented in MVC.

而已。如何以MVC方式实现Kohana分页库?哪个代码应该转到模型?到控制器?对视图?我看过很多例子,但没有一个在MVC中实现。

2 个解决方案

#1


1  

Pagination has two parts: the records filter part which should go in the controller and the display part which goes into the view. The example in the pagination library help is correct.

分页有两部分:记录过滤器部分应该进入控制器,显示部分进入视图。分页库帮助中的示例是正确的。

If you want to implement your own pagination library take a look here.

如果你想实现自己的分页库,请看这里。

#2


0  

To fulfill the MVC philosophy, you could: 1) have 2 methods in a model which make the same query but one returns only the row count and the other returns the actual result, being able to apply a LIMIT and an OFFSET. Let's say, Some_Model::get_results() and Some_Model::get_result_count()

为了实现MVC理念,您可以:1)在模型中有两个方法可以进行相同的查询,但是一个只返回行计数而另一个返回实际结果,能够应用LIMIT和OFFSET。比方说,Some_Model :: get_results()和Some_Model :: get_result_count()

2) In your controller, when pagination is needed, you call Some_Model::get_result_count() to know the total quantity of rows, and pass that value to Kohana's pagination initialization, to get the pages links, which you put into a variable to pass to the view.

2)在你的控制器中,当需要分页时,你调用Some_Model :: get_result_count()来知道行的总数,并将该值传递给Kohana的分页初始化,以获取页面链接,你将它放入变量中以通过到了视野。

3) In the view, you echo the variable that has the pages links, and voila!

3)在视图中,您回显具有页面链接的变量,瞧!

Of course this assumes you read the Kohana documentation for pagination and its examples. Hope it helps.

当然,这假设您阅读了Kohana文档的分页及其示例。希望能帮助到你。

#1


1  

Pagination has two parts: the records filter part which should go in the controller and the display part which goes into the view. The example in the pagination library help is correct.

分页有两部分:记录过滤器部分应该进入控制器,显示部分进入视图。分页库帮助中的示例是正确的。

If you want to implement your own pagination library take a look here.

如果你想实现自己的分页库,请看这里。

#2


0  

To fulfill the MVC philosophy, you could: 1) have 2 methods in a model which make the same query but one returns only the row count and the other returns the actual result, being able to apply a LIMIT and an OFFSET. Let's say, Some_Model::get_results() and Some_Model::get_result_count()

为了实现MVC理念,您可以:1)在模型中有两个方法可以进行相同的查询,但是一个只返回行计数而另一个返回实际结果,能够应用LIMIT和OFFSET。比方说,Some_Model :: get_results()和Some_Model :: get_result_count()

2) In your controller, when pagination is needed, you call Some_Model::get_result_count() to know the total quantity of rows, and pass that value to Kohana's pagination initialization, to get the pages links, which you put into a variable to pass to the view.

2)在你的控制器中,当需要分页时,你调用Some_Model :: get_result_count()来知道行的总数,并将该值传递给Kohana的分页初始化,以获取页面链接,你将它放入变量中以通过到了视野。

3) In the view, you echo the variable that has the pages links, and voila!

3)在视图中,您回显具有页面链接的变量,瞧!

Of course this assumes you read the Kohana documentation for pagination and its examples. Hope it helps.

当然,这假设您阅读了Kohana文档的分页及其示例。希望能帮助到你。