Kohana 3.1 分页链接问题

发布于 2024-12-01 10:29:43 字数 1426 浏览 0 评论 0原文

我已经在 Kohana 3.1 中使用控制器页面中的以下代码完成了分页。如何在我的视图页面中显示分页链接?这是正确的方法吗???或者我的代码有任何问题吗?

public function action_imagelist()
       {  
         $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();

// print_r($results);
 $page_links = $pagination;
 $this->template->content=$view->render();

} 

I have done the pagination in Kohana 3.1 using the following code in my controller page .How can I display the Pagination links in my view page ? Is this the correct way ??? or any issue with my code ?

public function action_imagelist()
       {  
         $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();

// print_r($results);
 $page_links = $pagination;
 $this->template->content=$view->render();

} 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬花如无物 2024-12-08 10:29:44

要显示分页,请在视图中打印 $page_links

您应该阅读 MVC 模式

To display pagination, in your view print out $page_links.

You should read how stuff is divided in MVC pattern!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文