代码之家  ›  专栏  ›  技术社区  ›  AdamB

Kohana 3分页

  •  6
  • AdamB  · 技术社区  · 15 年前

    我真的对科哈纳3的分页工作迷路了。Kohana3在任何地方都有分页的好例子吗?

    3 回复  |  直到 14 年前
        1
  •  14
  •   Kemo    15 年前
            // 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
    

        2
  •  3
  •   Kannan Prasad    14 年前

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

    Request::$uri

    Request::current()->uri() Request::current()->uri

        3
  •  2
  •   geca    14 年前
    推荐文章