Take the 2-minute tour ×

I have a problem. My Kohana pagination script not working correctly. Must have as follows : [], but I have the following - [] and records from database in home page are 2 (total records is 2, i set items_per_page to 1), but must have a 1 record only. Where is the problem?


public function action_index()
      $pagination = Pagination::factory(array(
        'total_items'=> Model::factory('index')->get_count(),
        'items_per_page' => 1,));

      $articles_ = Model::factory('index')->do_magic();
      $this->template->page_title = 'Sākums';
      $this->template->site_name = Kohana::$config->load('common')->get('site_name'); 
      $this->template->content = View::factory('index/index')
              ->set('query', $articles_)
              ->set('pagjinaacija', $pagination->render()); 
      $this->template->styles[] = 'index/index';


foreach($query as $row) {
    echo '<h2>'.$row['title'].'</h2>';
    echo '<p style="margin:0">'.$row['content'].'</p>';
echo $pagjinaacija;

And model

Class Model_Index Extends Model {
    public function get_count() {
    return  DB::query(Database::SELECT, 'SELECT COUNT(*) AS count FROM posts')->execute()->get('count');

    public function do_magic() {
        $query = DB::query(Database::SELECT, 'SELECT * FROM posts ORDER By id DESC')->execute()->as_array();
        return $query;

share|improve this question
Deleting your questions would be unfair to the people who took their time to answer them. –  NullUserException Jan 6 '12 at 17:55
add comment

2 Answers

up vote 1 down vote accepted

There are 2 problems:

  1. You're not using url rewrite rules to rewrite /index.php?page=2 into /?page=2
  2. You're not actually using the page query parameter to filter your records returned from the db, so it'll display them all.

The pagination object is only used to render a pagination control, not perform the actual filtering of db records.

share|improve this answer
Allain, how to do it? –  reGative Sep 20 '11 at 18:27
add comment

you maybe set bootstrap.php:

Route::set('index_page','yourcontroller/index(/<page>)', array('page' => '[0-9]+'))
        'controller'    => 'yourcontroller',
        'action'    => 'index',
share|improve this answer
add comment

Your Answer


