Kohana 3 pagination

后端 未结 3 1450
轮回少年
轮回少年 2021-02-09 13:53

I\'m really lost on how pagination works in kohana 3. Is there a good example of pagination in Kohana 3 anywhere?

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-09 14:04

    In Kohana 3.1 pagination is not included. Download the module and put it in the modules folder. Enable the module in your application/bootstrap.php .This is my controller page. For further configuration copy the provided config file from modules/pagination/config/pagination.php to 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();
    

    You may get error ErrorException [ Notice ]: Undefined property: Request::$uri. in the pagination class (module). In order to fix fix it

    Use Request::current()->uri() instead of Request::current()->uri

提交回复
热议问题