【问题标题】:Kohana 3.1 Pagination Links IssueKohana 3.1 分页链接问题
【发布时间】:2011-11-04 08:43:19
【问题描述】:

我已经在我的控制器页面中使用以下代码在 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();

} 

【问题讨论】:

    标签: php pagination kohana


    【解决方案1】:

    要显示分页,在您的视图中打印出$page_links

    你应该阅读MVC pattern中的东西是如何划分的!

    【讨论】:

    • ,我知道打印出来会给出分页结果。我用Kohana 2.X已经1年多了。刚开始用K3.1这里的问题是打印出来的页面链接为<p class="pagination"> First Previous <strong>1</strong> <a href="#">2</a> <a href="#">3</a> <a href="#">4</a> <a href="#" rel="next">Next</a> <a href="#" rel="last">Last</a> </p> 没有页面重定向。我在 pagination 模块中是否缺少任何配置??。
    • 您可以编辑视图以进行分页。只需将'template' => 'over/the/rainbow' 传递给Pagination::factory()
    • 分页添加模板有什么用?我遇到的问题是,当我渲染分页对象时,我得到它是这样的`

      First Previous 1 2 3 最后一个

      `
    猜你喜欢
    • 1970-01-01
    • 2012-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-16
    • 1970-01-01
    • 2021-01-01
    相关资源
    最近更新 更多