views:

672

answers:

2

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.

A: 

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.

Tihauan
A: 

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()

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.

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

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

Petruza